From 68f282ab0152fb54374e7fd220d9fb2d448feb0e Mon Sep 17 00:00:00 2001 From: dgw Date: Sat, 27 Jun 2020 17:08:29 -0500 Subject: [PATCH] formatting: conditionally include ref owners in PR output If PR head branch is from a different repo (fork), include owner names in the refs. Otherwise, just stick to the branch names only. --- sopel_modules/github/formatting.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sopel_modules/github/formatting.py b/sopel_modules/github/formatting.py index 1699595..5aa7526 100644 --- a/sopel_modules/github/formatting.py +++ b/sopel_modules/github/formatting.py @@ -342,9 +342,6 @@ def fmt_pull_request_summary_message(payload=None): if not payload: payload = current_payload - base_ref = payload['pull_request']['base']['label'].split(':')[-1] - head_ref = payload['pull_request']['head']['label'].split(':')[-1] - action = payload['action'] if action == 'closed' and payload['pull_request']['merged']: action = 'merged' @@ -359,6 +356,14 @@ def fmt_pull_request_summary_message(payload=None): if action == 'merged' and actor != author: maybe_possessive = '%s\'s ' % author + base = fmt_branch(payload['pull_request']['base']['ref']) + head = fmt_branch(payload['pull_request']['head']['ref']) + base_repo = payload['pull_request']['base']['user']['login'] + head_repo = payload['pull_request']['base']['user']['login'] + if base_repo != head_repo: + base = "{}:{}".format(fmt_name(base_repo), base) + head = "{}:{}".format(fmt_name(head_repo), head) + return '[{}] {} {} {}pull request #{}: {} ({}...{})'.format( fmt_repo(payload['repository']['name']), fmt_name(actor), @@ -366,8 +371,8 @@ def fmt_pull_request_summary_message(payload=None): maybe_possessive, payload['pull_request']['number'], emojize(payload['pull_request']['title']), - fmt_branch(base_ref), - fmt_branch(head_ref)) + base, + head) def fmt_pull_request_title_edit(payload=None):