Getting issue comments JIRA python

Bobby en Bezemer picture Bobby en Bezemer · Feb 11, 2016 · Viewed 10.8k times · Source

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?

Answer

Hemaa mathavan picture Hemaa mathavan · Jun 10, 2016

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])