获得问题评论JIRA python

时间:2016-02-11 19:28:10

标签: python jira jira-rest-api

我正在尝试获取在某个搜索查询的JIRA中创建的问题的所有评论。我的查询非常简单:

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

但是,如果我尝试访问使用以下表示法创建的故障单的注释,则会出现密钥错误。

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

如果我尝试收到如下单个问题的评论,我可以访问评论:

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

如何通过search_issues()函数访问这些评论?

3 个答案:

答案 0 :(得分:7)

search_issues方法不返回注释字段,您必须通过设置相应的参数手动声明必须包含的字段。

只需在search_issue方法中包含'fields'和'json_result'参数,并将其设置为

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

现在您可以访问评论而不会出现密钥类型错误

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

答案 1 :(得分:4)

我在同样的问题上挣扎。假设"问题"是一个类型问题的对象," jira"根据{{​​3}}

,是JIRA类型的对象 issue.fields.comment.comments

应该工作,但字段对象没有任何键"评论"。

其中提到的另一个选项对我有用:

jira.comments(issue) 

因此,要使用它,您可以使用搜索结果中的问题并致电jira.comments。 E.g。

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

(我的库版本是1.0.3,python 2.7.10)

答案 2 :(得分:0)

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)