Skip to content

Commit f6feafa

Browse files
authored
Fix #1055: Add comment and resolution when setting status to Cancelled (#1060)
1 parent afbfd89 commit f6feafa

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

jbi/jira/service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ def update_issue_status(self, context: ActionContext, jira_status: str):
290290
issue_key = context.jira.issue
291291
assert issue_key # Until we have more fine-grained typing of contexts
292292

293+
kwargs = {}
294+
if jira_status == "Cancelled":
295+
kwargs["fields"] = {
296+
"comment": "Issue was cancelled.",
297+
"resolution": {"name": "Invalid"},
298+
}
299+
293300
logger.info(
294301
"Updating Jira status to %s",
295302
jira_status,
@@ -298,6 +305,7 @@ def update_issue_status(self, context: ActionContext, jira_status: str):
298305
return self.client.set_issue_status(
299306
issue_key,
300307
jira_status,
308+
**kwargs,
301309
)
302310

303311
def update_issue_summary(self, context: ActionContext):

tests/unit/jira/test_service.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,36 @@ def test_get_issue_reraises_other_erroring_status_codes(
174174
assert record.message == "Getting issue JBI-234"
175175

176176

177+
def test_update_issue_status_adds_comment_and_resolution_when_cancelled(
178+
jira_service, settings, mocked_responses, action_context_factory, capturelogs
179+
):
180+
context = action_context_factory(jira__issue="JBI-234")
181+
url = f"{settings.jira_base_url}rest/api/2/issue/JBI-234/transitions"
182+
183+
mocked_responses.add(
184+
responses.GET,
185+
url,
186+
json={"transitions": [{"name": "foo", "id": 42, "to": {"name": "Cancelled"}}]},
187+
)
188+
mocked_responses.add(
189+
responses.POST,
190+
url,
191+
match=[
192+
responses.matchers.json_params_matcher(
193+
{
194+
"transition": {"id": 42},
195+
"fields": {
196+
"comment": "Issue was cancelled.",
197+
"resolution": {"name": "Invalid"},
198+
},
199+
}
200+
)
201+
],
202+
)
203+
204+
jira_service.update_issue_status(context=context, jira_status="Cancelled")
205+
206+
177207
def test_update_issue_resolution(
178208
jira_service, settings, mocked_responses, action_context_factory, capturelogs
179209
):

0 commit comments

Comments
 (0)