Skip to content

feat(notifications platform): Send workflow and deploy Slack notifications#25286

Merged
ceorourke merged 12 commits into
masterfrom
ceorourke/API-1807
Apr 19, 2021
Merged

feat(notifications platform): Send workflow and deploy Slack notifications#25286
ceorourke merged 12 commits into
masterfrom
ceorourke/API-1807

Conversation

@ceorourke

@ceorourke ceorourke commented Apr 15, 2021

Copy link
Copy Markdown
Member

The notifications platform project allows users to receive workflow, project alert, and deploy notifications via Slack. This PR builds the payload to send Slack notifications for the following activities:

  • an issue is assigned
  • an issue is unassigned
  • an issue has been resolved
  • an issue has a comment
  • a release has been deployed
  • an issue has been resolved in a release
  • new processing issues (actually does this belong here? not sure if it's considered "workflow")
  • regression
  • issue alert (will be in another PR)

assigned

unassigned

resolved

comment

Comment thread src/sentry/integrations/slack/message_builder/issues.py Outdated
Comment thread src/sentry/integrations/slack/message_builder/issues.py Outdated
Comment thread src/sentry/integrations/slack/notify_action.py Outdated
Comment thread src/sentry/integrations/slack/notify_action.py Outdated
Comment thread src/sentry/integrations/slack/message_builder/issues.py Outdated
Comment thread src/sentry/integrations/slack/message_builder/notifications.py Outdated
Comment thread src/sentry/integrations/slack/message_builder/notifications.py Outdated
]:
short_id = context["group"].qualified_short_id
title = context["activity_name"]
text = context["text_description"]

@ceorourke ceorourke Apr 15, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the happiest with how this looks in the message - the short ID isn't a link and it's redundant since I have the short ID as a link in the footer. If I modify it I'll need custom logic for each type of notification to build the sentence though and I'm not sure it's worth it. We can make this better later on so that we can get something out.

Comment thread src/sentry/integrations/slack/notifications.py Outdated
Comment thread src/sentry/notifications/activity/base.py Outdated
@ceorourke ceorourke changed the title feat(notifications platform): Send Slack notification feat(notifications platform): Send workflow and deploy Slack notifications Apr 17, 2021
Comment thread src/sentry/integrations/slack/message_builder/notifications.py Outdated

@mgaeta mgaeta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some suggested refactors

def build_notification_attachment(notification):
links = notification.get_dm_links()
notification_type = notification.__class__.__name__
footer = build_notification_footer(links, notification_type)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should change build_notification_footer to take the ActivityNotification object and internally calculate links.

referrer = re.sub("Notification$", "Slack", notification_type)
settings_url = urljoin(links["settings_url"], "?referrer=" + referrer)

if notification_type == "ReleaseActivityNotification":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing against class name can be flakey because the names can change. You should instead compare against the value returned by .get_category().

"link_names": 1,
"attachments": json.dumps(attachment),
}
client = SlackClient()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move client = SlackClient() out of the for loop.

for external_actor in external_actors:
attachment = [build_notification_attachment(notification)]
payload = {
"token": external_actor.integration.metadata["access_token"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Slack external actors will have an integrations, but we should be defensive and check to make sure it exists.

return user_context

def get_title(self) -> str:
return str(self.get_context()["activity_name"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return self.get_activity_name()

return str(self.get_context()["activity_name"])

def get_dm_text(self) -> str:
return str(self.get_context()["text_description"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks likely to break because not every ActivityNotification has text_description in context. It might make more sense to add dm_description to .get_context() and use that field in build_attachment.

@mgaeta mgaeta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great 👍🏽

@ceorourke ceorourke merged commit 2391fd4 into master Apr 19, 2021
@ceorourke ceorourke deleted the ceorourke/API-1807 branch April 19, 2021 21:59
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants