-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate headline post actions with @headline_post_action (#92)
* Populate headline post actions with @headline_post_action Adds a decorator that allows easily populating actions in headline posts, so that we can add custom integrations there (e.g. PagerDuty). Also adds a post_to_thread method in HeadlinePost * Add docs + logging for @headline_post_action
- Loading branch information
Showing
9 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
SLACK_HEADLINE_POST_ACTION_MAPPINGS = {} | ||
|
||
|
||
def headline_post_action(order=0, func=None): | ||
"""headline_post_action | ||
Decorator that allows adding a button/action into the headline post. Should be attached | ||
to functions that take a HeadlinePost and return a Slack Action type (e.g. Button). | ||
Actions can be conditional - returning None means that no Action will be added. | ||
The order parameter determines the relative position the action appears in the post - | ||
actions will be ordered low-high from left to right. Actions with the same order number | ||
will be added in the order the decorator is executed, which depends on the order of file imports. | ||
Usage: | ||
@headline_post_action(100) | ||
def edit_incident(headline_post): | ||
return slack.block_kit.Button(":pencil2: Edit", EDIT_INCIDENT_BUTTON, value=headline_post.incident.pk) | ||
""" | ||
|
||
def _wrapper(fn): | ||
SLACK_HEADLINE_POST_ACTION_MAPPINGS[ | ||
order | ||
] = SLACK_HEADLINE_POST_ACTION_MAPPINGS.get(order, []) + [fn] | ||
logger.info(f"Registering headline post action {fn.__name__} with order {order}") | ||
return fn | ||
|
||
if func: | ||
return _wrapper(func) | ||
|
||
return _wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters