Skip to content

Commit 52cd0d3

Browse files
committed
Jira: update issue methods include all parameters #1414
1 parent 4c75460 commit 52cd0d3

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

atlassian/jira.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,15 +1525,50 @@ def delete_issue(self, issue_id_or_key: str, delete_subtasks: bool = True):
15251525
return self.delete(url, params=params)
15261526

15271527
# @todo merge with edit_issue method
1528-
def issue_update(self, issue_key: str, fields: Union[str, dict]):
1529-
log.info('Updating issue "%s" with "%s"', issue_key, fields)
1528+
# https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-put
1529+
def issue_update(
1530+
self,
1531+
issue_key: str,
1532+
fields: Union[str, dict],
1533+
update: Optional[dict[Any, Any]] = None,
1534+
history_metadata: Optional[dict[Any, Any]] = None,
1535+
properties: Optional[list[Any]] = None,
1536+
notify_users: bool = True,
1537+
):
1538+
"""
1539+
Updates a Jira issue with specified fields, updates, history metadata, and properties.
1540+
1541+
1542+
:param issue_key: The key or ID of the issue to update.
1543+
:param fields: A dictionary containing field updates.
1544+
:param update: A dictionary containing advanced updates (e.g., add/remove operations for labels).
1545+
:param history_metadata: Metadata for tracking the history of changes.
1546+
:param properties: A list of properties to add or update on the issue.
1547+
:param notify_users: Whether to notify users of the update. default: True
1548+
:return: Response from the PUT request.
1549+
"""
1550+
log.info(f'Updating issue "{issue_key}" with "{fields}", "{update}", "{history_metadata}", and "{properties}"')
1551+
15301552
base_url = self.resource_url("issue")
15311553
url = f"{base_url}/{issue_key}"
1532-
return self.put(url, data={"fields": fields})
1554+
params = {
1555+
"fields": fields,
1556+
"update": update or {},
1557+
"historyMetadata": history_metadata or {},
1558+
"properties": properties or [],
1559+
}
1560+
# Remove empty keys to avoid sending unnecessary data
1561+
params = {key: value for key, value in params.items() if value}
1562+
if notify_users is True:
1563+
params["notifyUsers"] = "true"
1564+
else:
1565+
params["notifyUsers"] = "false"
1566+
return self.put(url, data=params)
15331567

1568+
# https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-put
15341569
def edit_issue(self, issue_id_or_key: str, fields: Union[str, dict], notify_users: bool = True):
15351570
"""
1536-
Edits an issue from a JSON representation
1571+
Edits an issue fields from a JSON representation
15371572
The issue can either be updated by setting explicit the field
15381573
value(s) or by using an operation to change the field value
15391574

docs/jira.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,22 @@ Manage issues
245245
# Check issue deleted
246246
jira.issue_deleted(issue_key)
247247
248-
# Update issue
249-
jira.issue_update(issue_key, fields)
248+
# Update issue fields and history metadata
249+
issue_key="PROJECT-123",
250+
fields={"summary": "Updated summary", "priority": {"id": "2"}},
251+
update={
252+
"labels": [{"add": "triaged"}, {"remove": "blocker"}],
253+
"timetracking": [{"edit": {"originalEstimate": "2d", "remainingEstimate": "1d"}}]
254+
},
255+
history_metadata={
256+
"activityDescription": "Updated via API",
257+
"actor": {"id": "user123", "type": "application-user"},
258+
"type": "custom-update"
259+
},
260+
properties=[
261+
{"key": "customKey1", "value": "Custom Value 1"}
262+
]
263+
jira.issue_update(issue_key: str, fields: Union[str, dict], update: dict = None, history_metadata: dict = None, properties: list = None, notify_users: bool = True)
250264
251265
# Assign issue to user
252266
jira.assign_issue(issue_key, account_id)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ commands = black {[base]linting_targets} --exclude __pycache__
5050
[testenv:mypy]
5151
basepython = python3
5252
skip_install = true
53+
implicit_optional = true
5354
deps =
5455
mypy>=0.812
5556
commands = mypy --install-types --non-interactive atlassian/

0 commit comments

Comments
 (0)