Skip to content

Commit 0260507

Browse files
committed
Adjustments to set_jira_fields
- remove preliminary testing - won't be set by our automation - don't update non-empty fields
1 parent 77a6138 commit 0260507

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

beeai/mcp_server/jira_tools.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
# Jira custom field IDs
1313
SEVERITY_CUSTOM_FIELD = "customfield_12316142"
14-
PRELIMINARY_TESTING_CUSTOM_FIELD = "customfield_12321540"
1514
TARGET_END_CUSTOM_FIELD = "customfield_12313942"
1615

1716

@@ -84,30 +83,46 @@ def set_jira_fields(
8483
Field(description="List of Fix Version/s values (e.g., ['rhel-9.8'], ['rhel-9.7.z'])"),
8584
] = None,
8685
severity: Annotated[Severity | None, Field(description="Severity value")] = None,
87-
preliminary_testing: Annotated[
88-
PreliminaryTesting | None, Field(description="Preliminary Testing value")
89-
] = None,
9086
target_end: Annotated[datetime.date | None, Field(description="Target End value")] = None,
9187
) -> str:
9288
"""
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.
9490
"""
9591
if os.getenv("DRY_RUN", "False").lower() == "true":
9692
return "Dry run, not updating Jira fields"
9793

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}"
99104

100105
fields = {}
106+
current_fields = current_issue.get("fields", {})
107+
101108
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+
103113
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+
107118
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+
109123
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+
111126
try:
112127
response = requests.put(
113128
urljoin(os.getenv("JIRA_URL"), f"rest/api/2/issue/{issue_key}"),
@@ -117,7 +132,8 @@ def set_jira_fields(
117132
response.raise_for_status()
118133
except requests.RequestException as e:
119134
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}"
121137

122138

123139
def add_jira_comment(

0 commit comments

Comments
 (0)