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

♻️ ref(slack): fix slack webhook actions typing #77322

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

iamrajjoshi
Copy link
Member

fixing the typing for Slack webhook actions. i also removed some old non slack blockkit logic since we have GA'ed for a while and won't have to deal with interactions with the old messages.

@iamrajjoshi iamrajjoshi self-assigned this Sep 11, 2024
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 11, 2024
webhook_client = WebhookClient(response_url)
try:
webhook_client.send(
blocks=json_blocks,
blocks=response.get("blocks"),
Copy link
Member Author

Choose a reason for hiding this comment

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

don't need to do this, originally that orjson line only converted from single quotes to double quotes (i am assume this was because in pre-slack_sdk world, we needed to. the slack_sdk handles this for us, i verified this with my local setup

action_data = slack_request.data.get("actions")
if action_data:
Copy link
Member Author

Choose a reason for hiding this comment

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

don't need this since we have ga'ed blockkit for months now and won't be dealing with non-blockkit interactions.

@iamrajjoshi iamrajjoshi marked this pull request as ready for review September 11, 2024 17:27
@iamrajjoshi iamrajjoshi requested review from a team as code owners September 11, 2024 17:27
@@ -421,7 +423,7 @@ def __init__(
event: Event | GroupEvent | None = None,
tags: set[str] | None = None,
identity: RpcIdentity | None = None,
actions: Sequence[MessageAction] | None = None,
actions: Sequence[MessageAction | BlockKitMessageAction] | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

what is the difference between MessageAction and BlockKitMessageAction? should we always be using one over the other if we don't support non-block kit anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

ideally we should delete MessageAction, but i saw some places in our logic where we create a MessageAction payload to send to slack, so i want to slowly remove it so make sure we don't break changes since ff this is hard

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, as I mentioned here it seems like BlockKitMessageAction ought to extend MessageAction (assuming we need both).

The "TODO" comment on MessageAction suggests that its bottom four attributes (including block_id, which is confusing) ought to belong to some other subclass. But I agree with delaying that sort of refactoring for later.

I'm okay with using MessageAction | BlockKitMessageAction for type hints temporarily, but would consider changing BlockKitMessageAction to extend MessageAction instead.

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 73.80952% with 11 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/integrations/slack/webhooks/action.py 72.50% 6 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #77322      +/-   ##
==========================================
+ Coverage   78.12%   78.14%   +0.01%     
==========================================
  Files        6996     6967      -29     
  Lines      310293   309641     -652     
  Branches    50765    50658     -107     
==========================================
- Hits       242415   241963     -452     
- Misses      56156    61259    +5103     
+ Partials    11722     6419    -5303     

Comment on lines 251 to 254
if isinstance(error.detail, dict):
text = list(*error.detail.values())[0]
else:
text = str(error.detail[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically the type definition for error.detail allows lists and/or dictionaries to be nested recursively. It might be more correct to do something like the helper function I sketched out here.

Copy link
Member Author

Choose a reason for hiding this comment

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

i yoinked that helper into this pr 😄

Copy link
Contributor

@RyanSkonnord RyanSkonnord left a comment

Choose a reason for hiding this comment

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

👏

@iamrajjoshi iamrajjoshi merged commit 12d0447 into master Sep 23, 2024
49 of 50 checks passed
@iamrajjoshi iamrajjoshi deleted the raj/webhook-actions-typing branch September 23, 2024 21:20
harshithadurai pushed a commit that referenced this pull request Sep 24, 2024
fixing the typing for Slack webhook actions. i also removed some old non
slack blockkit logic since we have GA'ed for a while and won't have to
deal with interactions with the old messages.
0Calories pushed a commit that referenced this pull request Sep 25, 2024
fixing the typing for Slack webhook actions. i also removed some old non
slack blockkit logic since we have GA'ed for a while and won't have to
deal with interactions with the old messages.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants