Skip to content

Commit

Permalink
get_issue_status_changelog method
Browse files Browse the repository at this point in the history
  • Loading branch information
gkowalc committed Mar 22, 2024
1 parent 10ee67e commit 273401b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
29 changes: 11 additions & 18 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,14 +1082,7 @@ def issue(self, key, fields="*all", expand=None):
params["expand"] = expand
return self.get(url, params=params)

def get_issue(
self,
issue_id_or_key,
fields=None,
properties=None,
update_history=True,
expand=None
):
def get_issue(self, issue_id_or_key, fields=None, properties=None, update_history=True, expand=None):
"""
Returns a full representation of the issue for the given issue key
By default, all fields are returned in this get-issue resource
Expand Down Expand Up @@ -1869,21 +1862,21 @@ def set_issue_status(self, issue_key, status_name, fields=None, update=None):
if update is not None:
data["update"] = update
return self.post(url, data=data)
def get_issue_status_changlog(self, issue):

def get_issue_status_changelog(self, issue_id):
# Get the issue details with changelog
issue = self.get_issue(issue, expand="changelog")
issue_id = self.get_issue(issue_id, expand="changelog")
status_change_history = []
for history in issue['changelog']['histories']:
for item in history['items']:
for history in issue_id["changelog"]["histories"]:
for item in history["items"]:
# Check if the item is a status change
if item['field'] == 'status':
status_change_history.append({
'from': item['fromString'],
'to': item['toString'],
'date': history['created']
})
if item["field"] == "status":
status_change_history.append(
{"from": item["fromString"], "to": item["toString"], "date": history["created"]}
)

return status_change_history

def set_issue_status_by_transition_id(self, issue_key, transition_id):
"""
Setting status by transition_id
Expand Down
3 changes: 3 additions & 0 deletions docs/jira.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Manage issues
# Get issue transitions
jira.get_issue_transitions(issue_key)
# Get issue status change log
jira.get_issue_status_changelog(issue_key)
# Get status ID from name
jira.get_status_id_from_name(status_name)
Expand Down
9 changes: 9 additions & 0 deletions examples/jira/jira_get_issue_status_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from atlassian import Jira

jira_cloud = Jira(url="<url>", username="username", password="password")
jira_dc = Jira(url="url", token="<token>>")

# example use
jira_cloud.get_issue_status_changelog("TEST-1")
# example output:
# [{'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 comments on commit 273401b

Please sign in to comment.