Jira-Python : 我们如何通过传递对象来获取评论者姓名?
Jira-Python : How can we fetch the commentor name by passing object?
我正在尝试获取最近更新的问题中评论者姓名的数据。我将更新后的问题保存在列表中,当我在查询中传递列表时,它会给我:AttributeError: type object 'PropertyHolder' has no attribute 'comment'
,即使该问题存在评论。
有人可以帮忙吗?
下面是代码
def issue_tested(project_name, updated_from, updated_to):
print project_name, updated_from, updated_to
total_update=[]
total_update = jira.search_issues('project = %s AND updated >= %s and updated <= %s' % (project_name, updated_from, updated_to))
total_updated_length = len(total_update)
print total_update
print total_updated_length
print total_update[2]
issue = jira.issue(total_update[2])
print issue
print issue.fields.comment.comments[0].author.name
我遇到了问题,但它没有在打印中通过 issue.fields.comment.comments[0].author.name
。但是,当我直接分配问题时:issue = jira.issue('Issue_name')
,它会给我作者姓名。但是当它作为对象传递时显示属性错误。
PS:我现在不想使用 Script-Runner,因为它是付费的,您能在 python 内给我任何解决方案吗?
谢谢!
说明
您收到此错误的原因是默认情况下 search
方法 returns 与可导航字段有关:
By default, only navigable (*navigable) fields are returned in this
search resource. Note: the default is different in the get-issue
resource -- the default there all fields (*all).
当你执行issue
方法时:
issue = jira.issue(total_update[2])
您传递 issue
对象,而不是字符串。里面有一个条件:
if type(id) == Issue:
return id
即它只是 returns 来自 search
执行的原始方法,缺少 comment 字段。
解决方案
您可以要求 search
方法在结果中包含 comment 字段:
total_update = jira.search_issues(jql_str='project = %s AND updated >= %s and updated <= %s' % (project_name, updated_from, updated_to), fields='comment')
您可以通过问题的关键查询:
问题=jira.issue(total_update[2].key)
方法 #1 更可取,除非您需要针对某些特定问题征求意见。
我正在尝试获取最近更新的问题中评论者姓名的数据。我将更新后的问题保存在列表中,当我在查询中传递列表时,它会给我:AttributeError: type object 'PropertyHolder' has no attribute 'comment'
,即使该问题存在评论。
有人可以帮忙吗?
下面是代码
def issue_tested(project_name, updated_from, updated_to):
print project_name, updated_from, updated_to
total_update=[]
total_update = jira.search_issues('project = %s AND updated >= %s and updated <= %s' % (project_name, updated_from, updated_to))
total_updated_length = len(total_update)
print total_update
print total_updated_length
print total_update[2]
issue = jira.issue(total_update[2])
print issue
print issue.fields.comment.comments[0].author.name
我遇到了问题,但它没有在打印中通过 issue.fields.comment.comments[0].author.name
。但是,当我直接分配问题时:issue = jira.issue('Issue_name')
,它会给我作者姓名。但是当它作为对象传递时显示属性错误。
PS:我现在不想使用 Script-Runner,因为它是付费的,您能在 python 内给我任何解决方案吗?
谢谢!
说明
您收到此错误的原因是默认情况下 search
方法 returns 与可导航字段有关:
By default, only navigable (*navigable) fields are returned in this search resource. Note: the default is different in the get-issue resource -- the default there all fields (*all).
当你执行issue
方法时:
issue = jira.issue(total_update[2])
您传递 issue
对象,而不是字符串。里面有一个条件:
if type(id) == Issue:
return id
即它只是 returns 来自 search
执行的原始方法,缺少 comment 字段。
解决方案
您可以要求
search
方法在结果中包含 comment 字段:total_update = jira.search_issues(jql_str='project = %s AND updated >= %s and updated <= %s' % (project_name, updated_from, updated_to), fields='comment')
您可以通过问题的关键查询:
问题=jira.issue(total_update[2].key)
方法 #1 更可取,除非您需要针对某些特定问题征求意见。