Skip to content

Commit 413524b

Browse files
authored
[WIP] [JIRA] new method get_issue_status_changelog + docs + example +small improvement get_issue (#1357)
* fixing minor issue in scrap_regex_from_issue method * new Confluence method scrap_regex_from_page+ docs + examples * added method get_attachments_ids_from_page to jira.py
1 parent d4ef596 commit 413524b

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

atlassian/jira.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,13 +1082,7 @@ def issue(self, key, fields="*all", expand=None):
10821082
params["expand"] = expand
10831083
return self.get(url, params=params)
10841084

1085-
def get_issue(
1086-
self,
1087-
issue_id_or_key,
1088-
fields=None,
1089-
properties=None,
1090-
update_history=True,
1091-
):
1085+
def get_issue(self, issue_id_or_key, fields=None, properties=None, update_history=True, expand=None):
10921086
"""
10931087
Returns a full representation of the issue for the given issue key
10941088
By default, all fields are returned in this get-issue resource
@@ -1097,6 +1091,7 @@ def get_issue(
10971091
:param fields: str
10981092
:param properties: str
10991093
:param update_history: bool
1094+
:param expand: str
11001095
:return: issue
11011096
"""
11021097
base_url = self.resource_url("issue")
@@ -1109,11 +1104,9 @@ def get_issue(
11091104
params["fields"] = fields
11101105
if properties is not None:
11111106
params["properties"] = properties
1112-
if update_history is True:
1113-
params["updateHistory"] = "true"
1114-
if update_history is False:
1115-
params["updateHistory"] = "false"
1116-
1107+
if expand:
1108+
params["expand"] = expand
1109+
params["updateHistory"] = str(update_history).lower()
11171110
return self.get(url, params=params)
11181111

11191112
def epic_issues(self, epic, fields="*all", expand=None):
@@ -1867,6 +1860,20 @@ def set_issue_status(self, issue_key, status_name, fields=None, update=None):
18671860
data["update"] = update
18681861
return self.post(url, data=data)
18691862

1863+
def get_issue_status_changelog(self, issue_id):
1864+
# Get the issue details with changelog
1865+
response_get_issue = self.get_issue(issue_id, expand="changelog")
1866+
status_change_history = []
1867+
for history in response_get_issue["changelog"]["histories"]:
1868+
for item in history["items"]:
1869+
# Check if the item is a status change
1870+
if item["field"] == "status":
1871+
status_change_history.append(
1872+
{"from": item["fromString"], "to": item["toString"], "date": history["created"]}
1873+
)
1874+
1875+
return status_change_history
1876+
18701877
def set_issue_status_by_transition_id(self, issue_key, transition_id):
18711878
"""
18721879
Setting status by transition_id

docs/jira.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ Manage issues
248248
# Get issue transitions
249249
jira.get_issue_transitions(issue_key)
250250
251+
# Get issue status change log
252+
jira.get_issue_status_changelog(issue_key)
253+
251254
# Get status ID from name
252255
jira.get_status_id_from_name(status_name)
253256
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from atlassian import Jira
2+
3+
jira_cloud = Jira(url="<url>", username="username", password="password")
4+
jira_dc = Jira(url="url", token="<token>>")
5+
6+
# example use
7+
jira_cloud.get_issue_status_changelog("TEST-1")
8+
# example output:
9+
# [{'from': 'Closed', 'to': 'In Progress', 'date': '2024-03-17T17:22:29.524-0500'}, {'from': 'In Progress', 'to': 'Closed', 'date': '2024-03-17T14:33:07.317-0500'}, {'from': 'In Progress', 'to': 'In Progress', 'date': '2024-03-16T09:25:52.033-0500'}, {'from': 'To Do', 'to': 'In Progress', 'date': '2024-03-14T19:25:02.511-0500'}]

0 commit comments

Comments
 (0)