@@ -241,16 +241,21 @@ def assign_jira_user(self, context: ActionContext, email: str):
241
241
# There doesn't appear to be an easy way to verify that
242
242
# this user can be assigned to this issue, so just try
243
243
# and do it.
244
- return self .client .update_issue_field (
245
- key = issue_key ,
246
- fields = {"assignee" : {"accountId" : jira_user_id }},
244
+ return self .update_issue_field (
245
+ context , "assignee" , jira_user_id , wrap_value = "accountId"
247
246
)
248
247
except (requests_exceptions .HTTPError , IOError ) as exc :
249
248
raise ValueError (
250
249
f"Could not assign { jira_user_id } to issue { issue_key } "
251
250
) from exc
252
251
253
- def update_issue_named_field (self , context : ActionContext , field : str , value : str ):
252
+ def update_issue_field (
253
+ self ,
254
+ context : ActionContext ,
255
+ field : str ,
256
+ value : Any ,
257
+ wrap_value : Optional [str ] = None ,
258
+ ):
254
259
bug = context .bug
255
260
issue_key = context .jira .issue
256
261
logger .info (
@@ -260,9 +265,7 @@ def update_issue_named_field(self, context: ActionContext, field: str, value: st
260
265
bug .id ,
261
266
extra = context .model_dump (),
262
267
)
263
- fields : dict [str , Any ] = {
264
- field : {"name" : value },
265
- }
268
+ fields : dict [str , Any ] = {field : {wrap_value : value } if wrap_value else value }
266
269
response = self .client .update_issue_field (key = issue_key , fields = fields )
267
270
logger .info (
268
271
f"Updated { field } of Jira issue %s to %s for Bug %s" ,
@@ -290,34 +293,25 @@ def update_issue_status(self, context: ActionContext, jira_status: str):
290
293
291
294
def update_issue_summary (self , context : ActionContext ):
292
295
"""Update's an issue's summary with the description of an incoming bug"""
293
-
294
- bug = context .bug
295
- issue_key = context .jira .issue
296
- logger .info (
297
- "Update summary of Jira issue %s for Bug %s" ,
298
- issue_key ,
299
- bug .id ,
300
- extra = context .model_dump (),
301
- )
302
296
truncated_summary = markdown_to_jira (
303
- bug .summary or "" , max_length = JIRA_DESCRIPTION_CHAR_LIMIT
297
+ context .bug .summary or "" , max_length = JIRA_DESCRIPTION_CHAR_LIMIT
298
+ )
299
+ return self .update_issue_field (
300
+ context , field = "summary" , value = truncated_summary
304
301
)
305
- fields : dict [str , str ] = {
306
- "summary" : truncated_summary ,
307
- }
308
- jira_response = self .client .update_issue_field (key = issue_key , fields = fields )
309
- return jira_response
310
302
311
303
def update_issue_resolution (self , context : ActionContext , jira_resolution : str ):
312
304
"""Update the resolution of the Jira issue."""
313
- return self .update_issue_named_field (
314
- context , field = "resolution" , value = jira_resolution
305
+ return self .update_issue_field (
306
+ context ,
307
+ field = "resolution" ,
308
+ value = jira_resolution ,
309
+ wrap_value = "name" ,
315
310
)
316
311
317
312
def update_issue_components (
318
313
self ,
319
- issue_key : str ,
320
- project : str ,
314
+ context : ActionContext ,
321
315
components : Iterable [str ],
322
316
) -> tuple [Optional [dict ], set ]:
323
317
"""Attempt to add components to the specified issue
@@ -334,7 +328,9 @@ def update_issue_components(
334
328
missing_components = set (components )
335
329
jira_components = []
336
330
337
- all_project_components = self .client .get_project_components (project )
331
+ all_project_components = self .client .get_project_components (
332
+ context .jira .project
333
+ )
338
334
for comp in all_project_components :
339
335
if comp ["name" ] in missing_components :
340
336
jira_components .append ({"id" : comp ["id" ]})
@@ -343,13 +339,8 @@ def update_issue_components(
343
339
if not jira_components :
344
340
return None , missing_components
345
341
346
- logger .info (
347
- "attempting to add components '%s' to issue '%s'" ,
348
- "," .join (components ),
349
- issue_key ,
350
- )
351
- resp = self .client .update_issue_field (
352
- key = issue_key , fields = {"components" : jira_components }
342
+ resp = self .update_issue_field (
343
+ context , field = "components" , value = jira_components
353
344
)
354
345
return resp , missing_components
355
346
@@ -576,9 +567,9 @@ def check_jira_all_project_issue_types_exist(actions, _get_service):
576
567
action_issue_types = set (action .parameters .issue_type_map .values ())
577
568
project_issue_types = issue_types_by_project .get (action .jira_project_key , set ())
578
569
if missing_issue_types := action_issue_types - project_issue_types :
579
- missing_issue_types_by_project [
580
- action . jira_project_key
581
- ] = missing_issue_types
570
+ missing_issue_types_by_project [action . jira_project_key ] = (
571
+ missing_issue_types
572
+ )
582
573
if missing_issue_types_by_project :
583
574
return [
584
575
checks .Warning (
0 commit comments