From 37c4d47ba3f47c8eab45432668077eb614e2e9dc Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Fri, 8 Sep 2017 21:35:00 -0700 Subject: [PATCH] If PR author is the same as the committer, only mention them once. Closes https://github.com/python/miss-islington/issues/18 --- backport/backport_pr.py | 12 +++++++++--- backport/tasks.py | 4 ++-- backport/util.py | 11 ++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/backport/backport_pr.py b/backport/backport_pr.py index 079e779c..1ea5fddc 100644 --- a/backport/backport_pr.py +++ b/backport/backport_pr.py @@ -27,9 +27,15 @@ async def backport_pr(event, gh, *args, **kwargs): if label['name'].startswith("needs backport to")] if branches: - message = "🐍🍒⛏🤖 " \ - f"Thanks @{created_by} for the PR, and @{merged_by} for merging it 🌮🎉." \ - f"I'm working now to backport this PR to: {', '.join(branches)}." + thanks_to = "" + if created_by == merged_by: + thanks_to = f"Thanks @{created_by} for the PR 🌮🎉." + else: + thanks_to = f"Thanks @{created_by} for the PR, and @{merged_by} for merging it 🌮🎉." + message = f"""\ + {thanks_to}. I'm working now to backport this PR to: {', '.join(branches)}. + 🐍🍒⛏🤖 + """ util.comment_on_pr(issue_number, message) for branch in branches: diff --git a/backport/tasks.py b/backport/tasks.py index 655969ef..3cf9e60e 100644 --- a/backport/tasks.py +++ b/backport/tasks.py @@ -37,11 +37,11 @@ def backport_task(commit_hash, branch, *, issue_number, created_by, merged_by): cp.backport() except cherry_picker.BranchCheckoutException: util.comment_on_pr(issue_number, - f"""Sorry @{created_by} and @{merged_by}, I had trouble checking out the `{branch}` backport branch. + f"""Sorry {util.get_participants(created_by, merged_by)}, I had trouble checking out the `{branch}` backport branch. Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line.""") cp.abort_cherry_pick() except cherry_picker.CherryPickException: util.comment_on_pr(issue_number, - f"""Sorry, @{created_by} and @{merged_by}, I could not cleanly backport this to `{branch}` due to a conflict. + f"""Sorry, {util.get_participants(created_by, merged_by)}, I could not cleanly backport this to `{branch}` due to a conflict. Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line.""") cp.abort_cherry_pick() diff --git a/backport/util.py b/backport/util.py index c09e2dcd..e5652971 100644 --- a/backport/util.py +++ b/backport/util.py @@ -36,4 +36,13 @@ def is_cpython_repo(): subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) except subprocess.SubprocessError: return False - return True \ No newline at end of file + return True + + +def get_participants(created_by, merged_by): + participants = "" + if created_by == merged_by: + participants = f"@{created_by}" + else: + participants = f"@{created_by} and @{merged_by}" + return participants \ No newline at end of file