11
11
12
12
# Jira custom field IDs
13
13
SEVERITY_CUSTOM_FIELD = "customfield_12316142"
14
- PRELIMINARY_TESTING_CUSTOM_FIELD = "customfield_12321540"
15
14
TARGET_END_CUSTOM_FIELD = "customfield_12313942"
16
15
17
16
@@ -84,30 +83,46 @@ def set_jira_fields(
84
83
Field (description = "List of Fix Version/s values (e.g., ['rhel-9.8'], ['rhel-9.7.z'])" ),
85
84
] = None ,
86
85
severity : Annotated [Severity | None , Field (description = "Severity value" )] = None ,
87
- preliminary_testing : Annotated [
88
- PreliminaryTesting | None , Field (description = "Preliminary Testing value" )
89
- ] = None ,
90
86
target_end : Annotated [datetime .date | None , Field (description = "Target End value" )] = None ,
91
87
) -> str :
92
88
"""
93
- Updates the specified Jira issue, setting the specified fields (if provided) .
89
+ Updates the specified Jira issue, setting only the fields that are currently empty/unset .
94
90
"""
95
91
if os .getenv ("DRY_RUN" , "False" ).lower () == "true" :
96
92
return "Dry run, not updating Jira fields"
97
93
98
- return "Not updating Jira fields"
94
+ # First, get the current issue to check existing field values
95
+ try :
96
+ response = requests .get (
97
+ urljoin (os .getenv ("JIRA_URL" ), f"rest/api/2/issue/{ issue_key } " ),
98
+ headers = _get_jira_headers (os .getenv ("JIRA_TOKEN" )),
99
+ )
100
+ response .raise_for_status ()
101
+ current_issue = response .json ()
102
+ except requests .RequestException as e :
103
+ return f"Failed to get current issue details: { e } "
99
104
100
105
fields = {}
106
+ current_fields = current_issue .get ("fields" , {})
107
+
101
108
if fix_versions is not None :
102
- fields ["fixVersions" ] = [{"name" : fv } for fv in fix_versions ]
109
+ current_fix_versions = current_fields .get ("fixVersions" , [])
110
+ if not current_fix_versions :
111
+ fields ["fixVersions" ] = [{"name" : fv } for fv in fix_versions ]
112
+
103
113
if severity is not None :
104
- fields [SEVERITY_CUSTOM_FIELD ] = {"value" : severity .value }
105
- if preliminary_testing is not None :
106
- fields [PRELIMINARY_TESTING_CUSTOM_FIELD ] = {"value" : preliminary_testing .value }
114
+ current_severity = current_fields .get (SEVERITY_CUSTOM_FIELD )
115
+ if not current_severity .get ("value" ):
116
+ fields [SEVERITY_CUSTOM_FIELD ] = {"value" : severity .value }
117
+
107
118
if target_end is not None :
108
- fields [TARGET_END_CUSTOM_FIELD ] = {"value" : target_end .strftime ("%Y-%m-%d" )}
119
+ current_target_end = current_fields .get (TARGET_END_CUSTOM_FIELD )
120
+ if not current_target_end .get ("value" ):
121
+ fields [TARGET_END_CUSTOM_FIELD ] = target_end .strftime ("%Y-%m-%d" )
122
+
109
123
if not fields :
110
- return "No fields to update have been specified, not doing anything"
124
+ return f"No fields needed updating in { issue_key } "
125
+
111
126
try :
112
127
response = requests .put (
113
128
urljoin (os .getenv ("JIRA_URL" ), f"rest/api/2/issue/{ issue_key } " ),
@@ -117,7 +132,8 @@ def set_jira_fields(
117
132
response .raise_for_status ()
118
133
except requests .RequestException as e :
119
134
return f"Failed to set the specified fields: { e } "
120
- return f"Successfully set the specified fields in { issue_key } "
135
+
136
+ return f"Successfully updated { issue_key } "
121
137
122
138
123
139
def add_jira_comment (
0 commit comments