Python 和 JIRA 从特定问题中获取字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30615846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python and JIRA get fields from specific issue
提问by Kobi K
I'm trying to get all the fields and values from a specific issue my code:
我正在尝试从我的代码的特定问题中获取所有字段和值:
authenticated_jira = JIRA(options={'server': self.jira_server}, basic_auth=(self.jira_username, self.jira_password))
issue = authenticated_jira.issue(self.id)
print issue.fields()
Instead of returning the list of fields it returns:
它返回的不是返回字段列表:
<jira.resources.PropertyHolder object at 0x108431390>
采纳答案by Kobi K
Found using:
发现使用:
print self.issue_object.raw
which returns the raw json dictionary which can be iterate and manipulate.
它返回可以迭代和操作的原始 json 字典。
回答by ThePavolC
authenticated_jira = JIRA(options={'server': self.jira_server}, basic_auth=(self.jira_username, self.jira_password))
issue = authenticated_jira.issue(self.id)
for field_name in issue.raw['fields']:
print "Field:", field_name, "Value:", issue.raw['fields'][field_name]
Depends on field type, sometimes you get dictionary as a value and then you have to find the actual value you want.
取决于字段类型,有时您将字典作为值,然后您必须找到所需的实际值。
回答by E. Oregel
You can use issue.raw['fields']['desired_field']
, but this way is kind of indirectly accessing the field values, because what you get in return is not consistent. You get lists of strings, then just strings themselves, and then straight up values that don't have a key for you to access them with, so you'll have to iterate, count the location, and then parse to get value which is unreliable.
您可以使用issue.raw['fields']['desired_field']
,但这种方式是间接访问字段值,因为您得到的回报并不一致。您获得字符串列表,然后只是字符串本身,然后是没有键供您访问它们的直接值,因此您必须迭代,计算位置,然后解析以获取值不可靠。
Best way is to use issue.fields.customfield_#
This way you don't have to do any parsing through the .raw fields
Almost everything has a customfield
associated with it. You can pull just issues from REST API
to find customfield #'s, or some of the fields that you get from using .raw will have a customfield id that should look like "customfield_11111" and that's what you'll use.
最好的方法是使用issue.fields.customfield_#
这种方式,您不必通过.raw fields
几乎所有内容都customfield
与之关联进行任何解析。您可以从中提取问题REST API
以查找自定义字段#,或者您从使用 .raw 获得的某些字段将具有一个看起来像“customfield_11111”的自定义字段 ID,这就是您将要使用的。