From d936370d2319b0085c32c33012af26cfac30d65d Mon Sep 17 00:00:00 2001 From: zweack Date: Mon, 22 Mar 2021 00:31:01 +0530 Subject: [PATCH 1/3] initial commit for response function --- github.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github.py b/github.py index ee5f7aa..e287931 100644 --- a/github.py +++ b/github.py @@ -42,7 +42,7 @@ def lookupGithubFullName(gh_username): return user.get('name', '') -def notifyRecipient(data): +def prepareReviewResponse(data): pass From 18d34ecb6470f8af9344d2b564b39292319038be Mon Sep 17 00:00:00 2001 From: review-bot101 <80596860+review-bot101@users.noreply.github.com> Date: Thu, 22 Apr 2021 12:52:42 +0530 Subject: [PATCH 2/3] Apply suggestions from code review --- github.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github.py b/github.py index e287931..7ef6f38 100644 --- a/github.py +++ b/github.py @@ -42,7 +42,7 @@ def lookupGithubFullName(gh_username): return user.get('name', '') -def prepareReviewResponse(data): +def checkReviewResponse(data): pass From 48c64aede41d2390d8489bd59905a1c96df37a7e Mon Sep 17 00:00:00 2001 From: zweack Date: Thu, 22 Apr 2021 12:55:24 +0530 Subject: [PATCH 3/3] variable changes --- slackInt.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/slackInt.py b/slackInt.py index 388c9c4..9f7feaf 100644 --- a/slackInt.py +++ b/slackInt.py @@ -16,48 +16,48 @@ def notifyRecipient(data): def createSlackMessagePayload(data): - pr_metadata = getPullRequestMetadata(data) + prMetadata = getPullRequestMetadata(data) - msg_text = getMessage(pr_metadata, data) - message = buildPayload(msg_text, pr_metadata) + msgText = getMessage(prMetadata, data) + message = buildPayload(msgText, prMetadata) return message -def getMessage(pr_metadata, data): +def getMessage(prMetadata, data): if data.get('action') == 'review_requested': - actionMessage = 'asked by {author} to review a pull request'.format(author=pr_metadata.get('author')) + actionMessage = 'asked by {author} to review a pull request'.format(author=prMetadata.get('author')) elif data.get('action') == 'assigned': - actionMessage = 'assigned a pull request by {author}'.format(author=pr_metadata.get('author')) + actionMessage = 'assigned a pull request by {author}'.format(author=prMetadata.get('author')) else: actionMessage = 'pinged' - msg_text = "You've been {action}. Good luck!".format(action=actionMessage) - if pr_metadata.get('channel') == os.environ.get('DEFAULT_NOTIFICATION_CHANNEL'): + msgText = "You've been {action}. Good luck!".format(action=actionMessage) + if prMetadata.get('channel') == os.environ.get('DEFAULT_NOTIFICATION_CHANNEL'): github_username = getUnmatchedUserName(data) - msg_text = '{}! {}'.format(github_username, msg_text) + msgText = '{}! {}'.format(github_username, msgText) - return msg_text + return msgText -def buildPayload(msg_text, pr_metadata): +def buildPayload(msgText, prMetadata): message = { - "text": msg_text, + "text": msgText, "as_user": True, "link_names": True, - "channel": pr_metadata.get('channel'), + "channel": prMetadata.get('channel'), "attachments": [ { - "fallback": "<{}|{}>".format(pr_metadata.get('url'), pr_metadata.get('title')), + "fallback": "<{}|{}>".format(prMetadata.get('url'), prMetadata.get('title')), "color": "#36a64f", - "author_name": "{} pull request #{}".format(pr_metadata.get('repo'), pr_metadata.get('number')), - "author_link": pr_metadata.get('url'), + "author_name": "{} pull request #{}".format(prMetadata.get('repo'), prMetadata.get('number')), + "author_link": prMetadata.get('url'), "author_icon": "https://github.com/favicon.ico", - "title": pr_metadata.get('title'), - "title_link": pr_metadata.get('url'), - "text": pr_metadata.get('description'), + "title": prMetadata.get('title'), + "title_link": prMetadata.get('url'), + "text": prMetadata.get('description'), "footer": "PR Notifications by Magnitude", - "footer_icon": pr_metadata.get('author_image'), + "footer_icon": prMetadata.get('author_image'), "ts": int(datetime.datetime.now().timestamp()) } ] @@ -100,7 +100,7 @@ def getNotificationChannel(data): return channel -def getSlackUserNameByGithubUserName(github_username): # pylint: disable=invalid-name +def getSlackUserNameByGithubUserName(github_username): slack_client = SlackClient(os.environ.get('SLACK_BOT_TOKEN')) response = slack_client.api_call("users.list") users = response.get('members', [])