Skip to content
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

Trigger Slack notification for review response #7

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
30 changes: 15 additions & 15 deletions slackInt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def createSlackMessagePayload(data):
"""Create payload for slack notification."""
pr_metadata = getPullRequestMetadata(data)

msg_text = getMessage(pr_metadata, data)
message = buildPayload(msg_text, pr_metadata)
msgText = getMessage(prMetadata, data)
message = buildPayload(msgText, prMetadata)

return message

Expand All @@ -39,33 +39,33 @@ def getMessage(pr_metadata, data):
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):
"""Build slack notification payload from github action data."""
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())
}
]
Expand Down