John Carter
John Carter

Reputation: 6986

Fetching entire changelog for an issue in JIRA using jira-python

Using jira-python, I want to retrieve the entire changelog for a JIRA issue:

issues_returned = jira.search_issues(args.jql, expand='changelog')

I discovered that for issues with more than 100 entries in their changelog I am only receiving the first 100:

Screenshot from debugger

My question is how do I specify a startAt and make another call to get subsequent pages of the changelog (using python-jira)?

From this thread at Atlassian I see that API v3 provides an endpoint to get the change log directly:

/rest/api/3/issue/{issueIdOrKey}/changelog

but this doesn't seem to be accessible via jira-python. I'd like to avoid having to do the REST call directly and authenticate separately. Barring a way to do it directly via jira-python, is there a way to make a 'raw' REST API call from jira-python?

Upvotes: 3

Views: 2806

Answers (2)

Cribber
Cribber

Reputation: 2913

I'm not sure if the package / API got changed since the accepted answer, but it is not true anymore. I tested it today:

The startAt parameter only relates to the offset concerning the number of issues, not the changelog.

On a positive note, with expand="changelog" enabled the request seemingly returns all the changes at once for an issue anyway. I was able to test this with a changelog of 34.822 changes.

The parameter startAt has no influence on the number or offset of items in the changelog.

Full code example:

import jira
jira_client = jira.JIRA(JIRA_URL, token_auth=api_token)
return_value = jira_client.search_issues(
    jql_str=f"issue = {issue_key}",
    json_result=True,
    fields=["None"],
    expand="changelog",
)
return return_value["issues"][0]["changelog"]["histories"]

Upvotes: 2

Mason Hanson
Mason Hanson

Reputation: 131

In instances where more than 100 results are present, you'll need to edit the 'startAt' parameter when searching issues:

issues_returned = jira.search_issues(args.jql, expand='changelog', startAt=100)

You'll need to setup a statement that compares the 'total' and 'maxResults' data points, then run another query with a different 'startAt' parameter if the total is higher and append the two together.

Upvotes: 2

Related Questions