6

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?

2
  • Could you specify which JIRA library you're using? Commented Feb 11, 2016 at 19:36
  • I am using the python jira library. See below for the import comments that I am running: import jira from jira.client import JIRA Commented Feb 11, 2016 at 19:40

3 Answers 3

15

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])
Sign up to request clarification or add additional context in comments.

Comments

9

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)

1 Comment

use [comment.body for comment in comments] to get the text entered in the comment
8
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)

1 Comment

This is great although the bit of info I wanted was: comment.author.key which I found by printing comment.__dict__

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.