@@ -369,9 +369,7 @@ def _upgrade_jira_issue(client, downstream, issue, config):
369369 attach_link (client , downstream , remote_link )
370370
371371
372- def match_user (
373- emails : list [str ], client : jira .client , downstream : jira .Issue
374- ) -> Optional [str ]:
372+ def match_user (emails : list [str ], client : jira .client .JIRA ) -> Optional [str ]:
375373 """Match an upstream user to an assignable downstream user and return the
376374 downstream username; return None on failure.
377375 """
@@ -410,7 +408,7 @@ def match_user(
410408
411409
412410def assign_user (
413- client : jira .client , issue : Issue , downstream : jira .Issue , remove_all = False
411+ client : jira .client . JIRA , issue : Issue , downstream : jira .Issue , remove_all = False
414412):
415413 """
416414 Attempts to assign a JIRA issue to the correct
@@ -440,7 +438,7 @@ def assign_user(
440438 continue
441439
442440 # Try to match the upstream assignee's emails to a Jira user
443- match_name = match_user (emails , client , downstream )
441+ match_name = match_user (emails , client )
444442 if match_name :
445443 # Assign the downstream issue to the matched user
446444 downstream .update ({"assignee" : {"name" : match_name }})
@@ -762,8 +760,10 @@ def _update_jira_issue(existing, issue, client, config):
762760 _update_transition (client , existing , issue )
763761
764762 # Only execute 'on_close' events for listings that opt-in
765- log .info ("Attempting to update downstream issue on upstream closed event" )
766- _update_on_close (existing , issue , updates )
763+ # and when the issue is closed.
764+ if issue .status == "Closed" :
765+ log .info ("Attempting to update downstream issue on upstream closed event" )
766+ _update_on_close (existing , issue , updates )
767767
768768 log .info ("Done updating %s!" , issue .url )
769769
@@ -1133,23 +1133,14 @@ def _update_on_close(existing, issue, updates: list[UPDATE_ENTRY]):
11331133 """
11341134 for item in updates :
11351135 if isinstance (item , dict ):
1136- if on_close_updates := item .get ("on_close" ):
1136+ if new_labels := item .get ("on_close" , {}). get ( "apply_labels" , [] ):
11371137 break
11381138 else :
1139- on_close_updates = None
1140-
1141- if not on_close_updates :
1142- return
1143-
1144- if issue .status != "Closed" :
1145- return
1146-
1147- if "apply_labels" not in on_close_updates :
11481139 return
11491140
1150- log .info ("Applying 'on_close' labels to downstream Jira issue" )
11511141 existing_labels = set (existing .fields .labels )
1152- updated_labels = existing_labels .union (set (on_close_updates ["apply_labels" ]))
1142+ updated_labels = existing_labels .union (new_labels )
1143+ log .info ("Applying 'on_close' labels %s to downstream Jira issue" , updated_labels )
11531144 _update_jira_labels (existing , list (updated_labels ))
11541145
11551146
0 commit comments