Issues pulling change log using python
Asked Answered
G

1

5

I am trying to query and pull changelog details using python.

The below code returns the list of issues in the project.

issued = jira.search_issues('project=  proj_a', maxResults=5)

for issue in issued:
    print(issue)

I am trying to pass values obtained in the issue above

issues = jira.issue(issue,expand='changelog')
changelog = issues.changelog
projects = jira.project(project)

I get the below error on trying the above:

JIRAError: JiraError HTTP 404 url: https://abc.atlassian.net/rest/api/2/issue/issue?expand=changelog
text: Issue does not exist or you do not have permission to see it.

Could anyone advise as to where am I going wrong or what permissions do I need.

Please note, if I pass a specific issue_id in the above code it works just fine but I am trying to pass a list of issue_id

Gillam answered 20/6, 2019 at 18:53 Comment(0)
C
18

You can already receive all the changelog data in the search_issues() method so you don't have to get the changelog by iterating over each issue and making another API call for each issue. Check out the code below for examples on how to work with the changelog.

issues = jira.search_issues('project=  proj_a', maxResults=5, expand='changelog')
for issue in issues:
    print(f"Changes from issue: {issue.key} {issue.fields.summary}")
    print(f"Number of Changelog entries found: {issue.changelog.total}") # number of changelog entries (careful, each entry can have multiple field changes)

    for history in issue.changelog.histories:
        print(f"Author: {history.author}") # person who did the change
        print(f"Timestamp: {history.created}") # when did the change happen?
        print("\nListing all items that changed:")

        for item in history.items:
            print(f"Field name: {item.field}") # field to which the change happened
            print(f"Changed to: {item.toString}") # new value, item.to might be better in some cases depending on your needs.
            print(f"Changed from: {item.fromString}") # old value, item.from might be better in some cases depending on your needs.
            print()
    print()

Just to explain what you did wrong before when iterating over each issue: you have to use the issue.key, not the issue-resource itself. When you simply pass the issue, it won't be handled correctly as a parameter in jira.issue(). Instead, pass issue.key:

for issue in issues:
    print(issue.key)
    myIssue = jira.issue(issue.key, expand='changelog')
Cathartic answered 22/8, 2019 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.