-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[WIP][Slack] Catch All - Code cleanup #70169
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
Conversation
# Optional label. This falls back to name. | ||
label: str | None = None | ||
@dataclass(kw_only=True) | ||
class _BaseMessageAction: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a base class to reduce repeated fields and help ensure changes are consistent. Also helps understand what the difference is between the block kit variant and the original class
9f9e34e
to
1efe721
Compare
from sentry.notifications.utils.actions import MessageAction | ||
|
||
|
||
def get_slack_button(action: MessageAction) -> Mapping[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove a bunch of unused methods and functions
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #70169 +/- ##
==========================================
+ Coverage 79.84% 79.87% +0.03%
==========================================
Files 6509 6507 -2
Lines 289811 289998 +187
Branches 49928 49930 +2
==========================================
+ Hits 231406 231649 +243
+ Misses 57992 57936 -56
Partials 413 413
|
def _get_button_text(self) -> str: | ||
return self.name | ||
|
||
# TODO(mgaeta): Refactor this to be provider-agnostic | ||
selected_options: Sequence[Mapping[str, Any]] | None = None | ||
option_groups: Sequence[Mapping[str, Any]] | None = None | ||
block_id: str | None = None | ||
elements: Sequence[Mapping[str, Any]] | None = None | ||
def get_button(self) -> Mapping[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't need to be at the base class, but everything is so hard typed to MessageAction
that we can't simply move this to the block kit class, because this is really just needed for slack flows
@staticmethod | ||
def get_link_button(action: MessageAction) -> SlackBlock: | ||
return { | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": action.label, | ||
}, | ||
"accessory": { | ||
"type": "button", | ||
"text": {"type": "plain_text", "text": action.name, "emoji": True}, | ||
"style": action.style, | ||
"value": action.value, | ||
"url": action.url, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is needed in getsentry, will need to move slowly
94b7f17
to
5a17034
Compare
|
||
|
||
@dataclass | ||
class SlackMessageAction(BaseMessageAction): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this over from BlockKitMessageAction
to be more accurate to Slack specific namespace, and added helper functions so it's easier to enact on the object, and add tests to verify functionality and contracts
button = { | ||
"type": "button", | ||
"text": self._get_button_text(), | ||
} | ||
if self.value: | ||
button["action_id"] = self.value | ||
button["value"] = self.value | ||
|
||
if self.action_id: | ||
button["action_id"] = self.action_id | ||
|
||
if self.url: | ||
button["url"] = self.url | ||
button["value"] = "link_clicked" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could add some constants here to keep it safer
def _ignore_action(group: Group) -> SlackMessageAction | None: | ||
if group.issue_category == GroupCategory.FEEDBACK: | ||
return None | ||
|
||
if group.get_status() == GroupStatus.IGNORED: | ||
return SlackMessageAction( | ||
name="status", label="Mark as Ongoing", value="unresolved:ongoing" | ||
) | ||
|
||
return SlackMessageAction(name="status", label="Archive", value="archive_dialog") | ||
|
||
|
||
def _resolve_action(group: Group, project: Project) -> SlackMessageAction: | ||
if group.get_status() == GroupStatus.RESOLVED: | ||
return SlackMessageAction( | ||
name="unresolved:ongoing", label="Unresolve", value="unresolved:ongoing" | ||
) | ||
if not project.flags.has_releases: | ||
return SlackMessageAction(name="status", label="Resolve", value="resolved") | ||
|
||
return SlackMessageAction( | ||
name="status", | ||
label="Resolve", | ||
value="resolve_dialog", | ||
) | ||
|
||
|
||
def _assign_action(group: Group) -> SlackMessageAction: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved these out from being anonymous closures in a function to named functions that we can now test and enforce contracts
|
||
return {"type": "actions", "elements": actions_block} | ||
|
||
def build(self) -> SlackBlock: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broke this function down and added helper methods to make it easier to read and understand the flow. We can now also add tests to enforce individual logic and force contracts
if "name" in action_data | ||
] | ||
|
||
@classmethod | ||
def get_action_list( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored to use early returns for easier reading, and less indentations. Also pulled some common code out for more reusability
# Optional label. This falls back to name. | ||
label: str | None = None | ||
@dataclass(kw_only=True) | ||
class BaseMessageAction: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created a base class to help build off and capture commonalities
This pull request has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you add the label "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
While we were trying to add and make changes for features or bug fixes, we noticed a lot of complexity and low hanging issues that could be fixed to help make our lives and this code area easier and safer to work with.
In that vain, we're using this branch as a way to capture and check potential changes