-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(linear): Post comment on parent issue when state changes #248
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
base: main
Are you sure you want to change the base?
Changes from all commits
6a75b58
84c87ba
59bf766
186a5a5
cf6986d
d90c348
402fd54
15868de
a47afe1
0af5af7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from django.contrib.auth.models import User | ||
| from django.db import transaction | ||
| from django.utils import timezone | ||
| from jinja2 import Environment, TemplateError | ||
|
|
||
| from firetower.auth.models import ExternalProfile, ExternalProfileType | ||
| from firetower.auth.services import ( | ||
|
|
@@ -185,6 +186,50 @@ def _resolve_assignees( | |
|
|
||
| COMPLETED_STATUSES = {ActionItemStatus.DONE, ActionItemStatus.CANCELED} | ||
|
|
||
| _PARENT_STATUS_TEMPLATE_ENV = Environment(autoescape=False) | ||
|
|
||
|
|
||
| def _comment_parent_issue_status_change( | ||
| incident: Incident, | ||
| linear_service: LinearService, | ||
| target_state: str, | ||
| statuses: list[str], | ||
| ) -> None: | ||
| if not settings.LINEAR or not incident.linear_parent_issue_id: | ||
| return | ||
|
|
||
| template_key = ( | ||
| "PARENT_STATUS_COMMENT_COMPLETED" | ||
| if target_state == "completed" | ||
| else "PARENT_STATUS_COMMENT_STARTED" | ||
| ) | ||
| template_source = settings.LINEAR.get(template_key, "") | ||
| if not template_source or not template_source.strip(): | ||
| return | ||
|
|
||
| completed_action_items = sum( | ||
| 1 for s in statuses if s in {ActionItemStatus.DONE, ActionItemStatus.CANCELED} | ||
| ) | ||
| try: | ||
| comment = _PARENT_STATUS_TEMPLATE_ENV.from_string(template_source).render( | ||
| incident=incident, | ||
| total_action_items=len(statuses), | ||
| completed_action_items=completed_action_items, | ||
| target_state=target_state, | ||
| ) | ||
| except TemplateError: | ||
| logger.exception( | ||
| f"Failed to render parent status comment template for incident {incident.id}" | ||
| ) | ||
| return | ||
|
|
||
| try: | ||
| linear_service.create_comment(incident.linear_parent_issue_id, comment) | ||
| except Exception: | ||
| logger.exception( | ||
| f"Failed to post parent status comment for incident {incident.id}" | ||
| ) | ||
|
|
||
|
|
||
| def _update_parent_issue_status( | ||
| incident: Incident, linear_service: LinearService | ||
|
|
@@ -206,9 +251,18 @@ def _update_parent_issue_status( | |
| return | ||
|
|
||
| target_state = "completed" if all_complete else "started" | ||
|
|
||
| parent_issue = linear_service.get_issue(incident.linear_parent_issue_id) | ||
| if not parent_issue or parent_issue.get("state_type") == target_state: | ||
| return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same-type state skips updateMedium Severity The early return treats the parent as already in the desired workflow when Reviewed by Cursor Bugbot for commit 0af5af7. Configure here. |
||
|
|
||
| state_id = states.get(target_state) | ||
| if state_id: | ||
| linear_service.update_issue(incident.linear_parent_issue_id, state_id=state_id) | ||
| if state_id and linear_service.update_issue( | ||
| incident.linear_parent_issue_id, state_id=state_id | ||
| ): | ||
| _comment_parent_issue_status_change( | ||
| incident, linear_service, target_state, statuses | ||
| ) | ||
|
cursor[bot] marked this conversation as resolved.
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def _sync_parent_assignee(incident: Incident, linear_service: LinearService) -> None: | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.