-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(workflow_engine): Only link workflows to the IssueStream #112276
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
Draft
saponifi3d
wants to merge
8
commits into
master
Choose a base branch
from
jcallender/aci/organize-rule-defaults
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba3b6aa
Move the receivers/rules.py to receivers/project_workflows.py and
saponifi3d c38f41e
ensure the project workflow is registered correctly
saponifi3d 456aada
find / fix a few more places where receviers.rules was being referenced.
saponifi3d 45d3896
fix remaining mypy issues
saponifi3d 3d8966e
set the action interval to 0 by default on the default workflow
saponifi3d b9fca87
Make sure the data condition groups have the org associated
saponifi3d 43dea27
Fix some tests and make general improvements
saponifi3d 014e847
minor cleanup / info from a bot review
saponifi3d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,116 @@ | ||
| from typing import Sequence | ||
|
|
||
| from django.db import router, transaction | ||
|
|
||
| from sentry.models.organization import Organization | ||
| from sentry.models.project import Project | ||
| from sentry.notifications.models.notificationaction import ActionTarget | ||
| from sentry.notifications.types import FallthroughChoiceType | ||
| from sentry.workflow_engine.defaults.detectors import _ensure_detector | ||
| from sentry.workflow_engine.models import ( | ||
| Action, | ||
| DataCondition, | ||
| DataConditionGroup, | ||
| DataConditionGroupAction, | ||
| DetectorWorkflow, | ||
| Workflow, | ||
| WorkflowDataConditionGroup, | ||
| ) | ||
| from sentry.workflow_engine.models.data_condition import Condition | ||
| from sentry.workflow_engine.typings.grouptype import IssueStreamGroupType | ||
|
|
||
| DEFAULT_WORKFLOW_LABEL = "Send a notification for high priority issues" | ||
|
|
||
|
|
||
| def connect_workflows_to_issue_stream( | ||
| project: Project, | ||
| workflows: list[Workflow], | ||
| ) -> Sequence[DetectorWorkflow]: | ||
| # Because we don't know if this signal is handled already or not... | ||
| issue_stream_detector = _ensure_detector(project, IssueStreamGroupType.slug) | ||
|
|
||
| connections = [ | ||
| DetectorWorkflow( | ||
| workflow=workflow, | ||
| detector=issue_stream_detector, | ||
| ) | ||
| for workflow in workflows | ||
| ] | ||
| return DetectorWorkflow.objects.bulk_create( | ||
| connections, | ||
| ignore_conflicts=True, | ||
| ) | ||
|
|
||
|
|
||
| def create_priority_workflow(org: Organization) -> Workflow: | ||
| existing = Workflow.objects.filter(organization=org, name=DEFAULT_WORKFLOW_LABEL).first() | ||
| if existing: | ||
| return existing | ||
|
|
||
| with transaction.atomic(router.db_for_write(Workflow)): | ||
| when_condition_group = DataConditionGroup.objects.create( | ||
| logic_type=DataConditionGroup.Type.ANY_SHORT_CIRCUIT, | ||
| organization=org, | ||
| ) | ||
|
|
||
| workflow = Workflow.objects.create( | ||
| organization=org, | ||
| name=DEFAULT_WORKFLOW_LABEL, | ||
| when_condition_group=when_condition_group, | ||
| config={"frequency": 0}, | ||
| ) | ||
|
|
||
| # Create the workflow trigger conditions | ||
sentry-warden[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| conditions: list[DataCondition] = [] | ||
| conditions.append( | ||
| DataCondition( | ||
| type=Condition.NEW_HIGH_PRIORITY_ISSUE, | ||
| condition_group=workflow.when_condition_group, | ||
| comparison=True, | ||
| condition_result=True, | ||
| ) | ||
| ) | ||
| conditions.append( | ||
| DataCondition( | ||
| type=Condition.EXISTING_HIGH_PRIORITY_ISSUE, | ||
| condition_group=workflow.when_condition_group, | ||
| comparison=True, | ||
| condition_result=True, | ||
| ) | ||
| ) | ||
| DataCondition.objects.bulk_create(conditions) | ||
|
|
||
| # Create the Action | ||
| action_filter = DataConditionGroup.objects.create( | ||
| logic_type=DataConditionGroup.Type.ANY_SHORT_CIRCUIT, | ||
| organization=org, | ||
| ) | ||
|
|
||
| action = Action.objects.create( | ||
| type=Action.Type.EMAIL, | ||
| config={ | ||
| "target_type": ActionTarget.ISSUE_OWNERS, | ||
| "target_identifier": None, | ||
| }, | ||
| data={ | ||
| "fallthrough_type": FallthroughChoiceType.ACTIVE_MEMBERS.value, | ||
| }, | ||
| ) | ||
| DataConditionGroupAction.objects.create( | ||
| action=action, | ||
| condition_group=action_filter, | ||
| ) | ||
|
|
||
| WorkflowDataConditionGroup.objects.create( | ||
| workflow=workflow, | ||
| condition_group=action_filter, | ||
| ) | ||
|
|
||
| return workflow | ||
|
|
||
|
|
||
| def ensure_default_workflows(project: Project) -> list[Workflow]: | ||
| workflows = [create_priority_workflow(project.organization)] | ||
| connect_workflows_to_issue_stream(project, workflows) | ||
|
|
||
| return workflows | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.