@@ -677,10 +677,26 @@ def add_issues_to_epic(jira, obj, epic_id, issue_keys, ignore_epics=True):
677677 try :
678678 return jira .add_issues_to_epic (epic_id = epic_id , issue_keys = issue_keys , ignore_epics = ignore_epics )
679679 except JIRAError as e :
680- logger .error ("error adding issues %s to epic %s for %s" , issue_keys , epic_id , obj .id )
681- logger .exception (e )
682- log_jira_alert (e .text , obj )
683- return False
680+ """
681+ We must try to accommodate the following:
682+
683+ The request contains a next-gen issue. This operation can't add next-gen issues to epics.
684+ To add a next-gen issue to an epic, use the Edit issue operation and set the parent property
685+ (i.e., '"parent":{"key":"PROJ-123"}' where "PROJ-123" has an issue type at level one of the issue type hierarchy).
686+ See <a href="https://developer.atlassian.com/cloud/jira/platform/rest/v2/"> developer.atlassian.com </a> for more details.
687+ """
688+ try :
689+ if "The request contains a next-gen issue." in str (e ):
690+ # Attempt to update the issue manually
691+ for issue_key in issue_keys :
692+ issue = jira .issue (issue_key )
693+ epic = jira .issue (epic_id )
694+ issue .update (parent = {"key" : epic .key })
695+ except JIRAError as e :
696+ logger .error ("error adding issues %s to epic %s for %s" , issue_keys , epic_id , obj .id )
697+ logger .exception (e )
698+ log_jira_alert (e .text , obj )
699+ return False
684700
685701
686702# we need two separate celery tasks due to the decorators we're using to map to/from ids
@@ -1284,13 +1300,12 @@ def update_epic(engagement, **kwargs):
12841300 if not epic_name :
12851301 epic_name = engagement .name
12861302
1287- epic_priority = kwargs .get ("epic_priority" )
1288-
12891303 jira_issue_update_kwargs = {
12901304 "summary" : epic_name ,
12911305 "description" : epic_name ,
1292- "priority" : {"name" : epic_priority },
12931306 }
1307+ if (epic_priority := kwargs .get ("epic_priority" )) is not None :
1308+ jira_issue_update_kwargs ["priority" ] = {"name" : epic_priority }
12941309 issue .update (** jira_issue_update_kwargs )
12951310 return True
12961311 except JIRAError as e :
@@ -1319,6 +1334,7 @@ def add_epic(engagement, **kwargs):
13191334 jira_instance = get_jira_instance (engagement )
13201335 if jira_project .enable_engagement_epic_mapping :
13211336 epic_name = kwargs .get ("epic_name" )
1337+ epic_issue_type_name = getattr (jira_project , "epic_issue_type_name" , "Epic" )
13221338 if not epic_name :
13231339 epic_name = engagement .name
13241340 issue_dict = {
@@ -1328,14 +1344,16 @@ def add_epic(engagement, **kwargs):
13281344 "summary" : epic_name ,
13291345 "description" : epic_name ,
13301346 "issuetype" : {
1331- "name" : getattr ( jira_project , " epic_issue_type_name" , "Epic" ) ,
1347+ "name" : epic_issue_type_name ,
13321348 },
1333- get_epic_name_field_name (jira_instance ): epic_name ,
13341349 }
13351350 if kwargs .get ("epic_priority" ):
13361351 issue_dict ["priority" ] = {"name" : kwargs .get ("epic_priority" )}
13371352 try :
13381353 jira = get_jira_connection (jira_instance )
1354+ # Determine if we should add the epic name or not
1355+ if (epic_name_field := get_epic_name_field_name (jira_instance )) in get_issuetype_fields (jira , jira_project .project_key , epic_issue_type_name ):
1356+ issue_dict [epic_name_field ] = epic_name
13391357 logger .debug ("add_epic: %s" , issue_dict )
13401358 new_issue = jira .create_issue (fields = issue_dict )
13411359 j_issue = JIRA_Issue (
0 commit comments