Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Append Co-authored-by: in the commit message. #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cherry_picker/cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def amend_commit_message(self, cherry_pick_branch):
commit_prefix = ""
if self.prefix_commit:
commit_prefix = f"[{get_base_branch(cherry_pick_branch)}] "
updated_commit_message = f"{commit_prefix}{self.get_commit_message(self.commit_sha1)}{os.linesep}(cherry picked from commit {self.commit_sha1})"
updated_commit_message = f"""{commit_prefix}{self.get_commit_message(self.commit_sha1)}
(cherry picked from commit {self.commit_sha1})

Co-authored-by: {get_author_info_from_short_sha(self.commit_sha1)}"""
updated_commit_message = updated_commit_message.replace('#', 'GH-')
if self.dry_run:
click.echo(f" dry-run: git commit --amend -m '{updated_commit_message}'")
Expand Down Expand Up @@ -295,7 +298,11 @@ def continue_cherry_pick(self):
short_sha = cherry_pick_branch[cherry_pick_branch.index('-')+1:cherry_pick_branch.index(base)-1]
full_sha = get_full_sha_from_short(short_sha)
commit_message = self.get_commit_message(short_sha)
updated_commit_message = f'[{base}] {commit_message}. \n(cherry picked from commit {full_sha})'
co_author_info = f"Co-authored-by: {get_author_info_from_short_sha(short_sha)}"
updated_commit_message = f"""[{base}] {commit_message}.
(cherry picked from commit {full_sha})

{co_author_info}"""
if self.dry_run:
click.echo(f" dry-run: git commit -am '{updated_commit_message}' --allow-empty")
else:
Expand Down Expand Up @@ -389,6 +396,13 @@ def get_full_sha_from_short(short_sha):
return full_sha


def get_author_info_from_short_sha(short_sha):
cmd = f"git log -1 --format='%aN <%ae>' {short_sha}"
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
author = output.strip().decode('utf-8')
return author


def is_cpython_repo():
cmd = "git log -r 7f777ed95a19224294949e1b4ce56bbffcb1fe9f"
try:
Expand Down
26 changes: 21 additions & 5 deletions cherry_picker/cherry_picker/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest

from .cherry_picker import get_base_branch, get_current_branch, \
get_full_sha_from_short, is_cpython_repo, CherryPicker, \
get_full_sha_from_short, get_author_info_from_short_sha, \
is_cpython_repo, CherryPicker, \
normalize_commit_message


Expand Down Expand Up @@ -44,6 +45,13 @@ def test_get_full_sha_from_short(subprocess_check_output):
assert get_full_sha_from_short('22a594a') == '22a594a0047d7706537ff2ac676cdc0f1dcb329c'


@mock.patch('subprocess.check_output')
def test_get_author_info_from_short_sha(subprocess_check_output):
mock_output = b"Armin Rigo <[email protected]>"
subprocess_check_output.return_value = mock_output
assert get_author_info_from_short_sha('22a594a') == 'Armin Rigo <[email protected]>'


@mock.patch('os.path.exists')
def test_sorted_branch(os_path_exists):
os_path_exists.return_value = True
Expand Down Expand Up @@ -119,18 +127,26 @@ def test_normalize_long_commit_message():
The `Show Source` was broken because of a change made in sphinx 1.5.1
In Sphinx 1.4.9, the sourcename was "index.txt".
In Sphinx 1.5.1+, it is now "index.rst.txt".
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)

Co-authored-by: Elmar Ritsch <[email protected]>"""
title, body = normalize_commit_message(commit_message)
assert title == "[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)"
assert body == """The `Show Source` was broken because of a change made in sphinx 1.5.1
In Sphinx 1.4.9, the sourcename was "index.txt".
In Sphinx 1.5.1+, it is now "index.rst.txt".
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)

Co-authored-by: Elmar Ritsch <[email protected]>"""

def test_normalize_short_commit_message():
commit_message = """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)

(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)

Co-authored-by: Elmar Ritsch <[email protected]>"""
title, body = normalize_commit_message(commit_message)
assert title == "[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)"
assert body == """(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
assert body == """(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)

Co-authored-by: Elmar Ritsch <[email protected]>"""