Skip to content

Fix #1055: Add comment and resolution when setting status to Cancelled #1060

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

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jbi/jira/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ def update_issue_status(self, context: ActionContext, jira_status: str):
issue_key = context.jira.issue
assert issue_key # Until we have more fine-grained typing of contexts

kwargs = {}
if jira_status == "Cancelled":
kwargs["fields"] = {
"comment": "Issue was cancelled.",
"resolution": {"name": "Invalid"},
}

logger.info(
"Updating Jira status to %s",
jira_status,
Expand All @@ -298,6 +305,7 @@ def update_issue_status(self, context: ActionContext, jira_status: str):
return self.client.set_issue_status(
issue_key,
jira_status,
**kwargs,
)

def update_issue_summary(self, context: ActionContext):
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/jira/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,36 @@ def test_get_issue_reraises_other_erroring_status_codes(
assert record.message == "Getting issue JBI-234"


def test_update_issue_status_adds_comment_and_resolution_when_cancelled(
jira_service, settings, mocked_responses, action_context_factory, capturelogs
):
context = action_context_factory(jira__issue="JBI-234")
url = f"{settings.jira_base_url}rest/api/2/issue/JBI-234/transitions"

mocked_responses.add(
responses.GET,
url,
json={"transitions": [{"name": "foo", "id": 42, "to": {"name": "Cancelled"}}]},
)
mocked_responses.add(
responses.POST,
url,
match=[
responses.matchers.json_params_matcher(
{
"transition": {"id": 42},
"fields": {
"comment": "Issue was cancelled.",
"resolution": {"name": "Invalid"},
},
}
)
],
)

jira_service.update_issue_status(context=context, jira_status="Cancelled")


def test_update_issue_resolution(
jira_service, settings, mocked_responses, action_context_factory, capturelogs
):
Expand Down
Loading