Getting issue comments JIRA python

13,450

Solution 1

The comment field is not returned by the search_issues method you have to manually state the fields that must be included by setting the corresponding parameter.

just include the 'fields' and 'json_result' parameter in the search_issue method and set it like this

open_issues = jira_object.search_issues('project = Support AND issuetype = Incident AND \
    (status = "Open" OR status = "Resolved" OR status = "Waiting For Customer")', maxResults = 100,expand='changelog',fields = 'comment',json_result ='True')

Now you can access the comments without getting keytype error

comm=([issue.raw['fields']['comment']['comments'] for issue in open_issues])

Solution 2

I struggled with the same issue. Assuming "issue" is an object of type Issue, and "jira" is an object of type JIRA, according to http://jira.readthedocs.org/en/latest/#issues

issue.fields.comment.comments

should work, but the fields object does not have any key "comment".

The other option mentioned there works for me:

jira.comments(issue) 

So, for it to work you use the issues from your search result and call jira.comments. E.g.

issues =  jira.search_issues(query)
comments = jira.comments(issues[index])

(My version of the library is 1.0.3, python 2.7.10)

Solution 3

from jira import JIRA

Jira =  JIRA('https://jira.atlassian.com')

issue_num = "ISSUE-123"

issue = Jira.issue(issue_num)

comments =  issue.fields.comment.comments

for comment in comments:
    print("Comment text : ",comment.body)
    print("Comment author : ",comment.author.displayName)
    print("Comment time : ",comment.created)
Share:
13,450
Bobby en Bezemer
Author by

Bobby en Bezemer

Updated on June 19, 2022

Comments

  • Bobby en Bezemer
    Bobby en Bezemer about 2 years

    I am trying to get all comments of issues created in JIRA of a certain search query. My query is fairly simple:

    import jira
    from jira.client import JIRA
    
    def fetch_tickets_open_yesterday(jira_object):
        # JIRA query to fetch the issues
        open_issues = jira_object.search_issues('project = Support AND issuetype = Incident AND \
        (status = "Open" OR status = "Resolved" OR status = "Waiting For Customer")', maxResults = 100,expand='changelog')
    
        # returns all open issues
        return open_issues
    

    However, if I try to access the comments of tickets created using the following notation, I get a key error.

    for issue in issues:
        print issue.raw['fields']['comment']
    

    If I try to get comments of a single issue like below, I can access the comments:

    single_issue = jira_object.issue('SUP-136834')
    single_issue.raw['fields']['comment']
    

    How do I access these comments through search_issues() function?

  • REdim.Learning
    REdim.Learning almost 6 years
    use [comment.body for comment in comments] to get the text entered in the comment