如何在 Jira 中获取自定义字段的选项?
How to get the options for a custom field in Jira?
在我查看的 Jira 问题中,有些字段带有有效值的下拉列表。我想使用 python 访问该下拉列表。查看问题的 returned 字段时,该对象的值 customfield_14651
是一个具有 value
和 id
的对象。 Jira documentation 显示有一个 custom_field_option()
方法应该 return 字段?我调用如下方法:
self.jira = JIRA('https://jira.companyname.com',basic_auth (login['username'], login['password']) )
print self.jira.custom_field_option('14651')
并收到以下错误:
response text = {"errorMessages":["A custom field option with id '14651' does not exist"],"errors":{}}
Jira 具有 .fields()
功能,该功能 returns 您正在使用的帐户可见的所有字段的列表。
from jira import JIRA
jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})
# Fetch all fields
allfields = jira.fields()
# Make a map from field name -> field id
name_map = {field['name']:field['id'] for field in allfields}
name_map
现在是 {"field name":"customfield_xxxx", ... }
格式的字典
在 API 中执行此操作的方法似乎是:
from jira import JIRA
jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})
# get an example issue that has the field you're interested in
issue = jira("PRJ-1")
meta = jira.editmeta(issue)
# inspect the meta to get the field you want to look at
allowed_values = [v['value'] for v in meta['fields']['customfield_99999']['allowedValues']]
在我查看的 Jira 问题中,有些字段带有有效值的下拉列表。我想使用 python 访问该下拉列表。查看问题的 returned 字段时,该对象的值 customfield_14651
是一个具有 value
和 id
的对象。 Jira documentation 显示有一个 custom_field_option()
方法应该 return 字段?我调用如下方法:
self.jira = JIRA('https://jira.companyname.com',basic_auth (login['username'], login['password']) )
print self.jira.custom_field_option('14651')
并收到以下错误:
response text = {"errorMessages":["A custom field option with id '14651' does not exist"],"errors":{}}
Jira 具有 .fields()
功能,该功能 returns 您正在使用的帐户可见的所有字段的列表。
from jira import JIRA
jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})
# Fetch all fields
allfields = jira.fields()
# Make a map from field name -> field id
name_map = {field['name']:field['id'] for field in allfields}
name_map
现在是 {"field name":"customfield_xxxx", ... }
在 API 中执行此操作的方法似乎是:
from jira import JIRA
jira = JIRA(basic_auth=('username', 'password'), options = {'server': 'url'})
# get an example issue that has the field you're interested in
issue = jira("PRJ-1")
meta = jira.editmeta(issue)
# inspect the meta to get the field you want to look at
allowed_values = [v['value'] for v in meta['fields']['customfield_99999']['allowedValues']]