首页 > 解决方案 > 通过 Jira REST API 从 CustomFieldOption 数组中获取“值”

问题描述

我有一些代码通过 REST API 连接到 Jira,检索一些数据并将其打印回屏幕。这里是:

prod_server = 'https://jira.abc.com'
cust_session = JIRA(server=prod_server, basic_auth=(<user_name>, <password>))

issue = cust_session.issue('MED-98', expand='changelog')
changelog = issue.changelog

for history in changelog.histories:
    for item in history.items:
        if item.field == 'status' and item.fromString == 'Pending Approval':
            print('Key:', issue.key, 'Category:', issue.fields.customfield_8361, ' Time:', history.created, 'By:', history.author)

这导致:

Key: MED-98   Category:  [<JIRA CustomFieldOption: value='Marketing', id='37394'>]  Time:  2021-03-15T08:20:08.484  By:  Smith, James
Key: MED-98   Category:  [<JIRA CustomFieldOption: value='Marketing', id='37394'>]  Time:  2021-03-12T19:22:20.583  By:  Jones, Mary

由于category是自定义字段 ( customfield_8361),因此它作为包含其和的数组输出。valueid

是否可以value输出(而不是整个数组)?

我的目标是使输出如下所示:

Key: MED-98   Category: Marketing   Time: 2021-03-15T08:20:08.484   By: Smith, James
Key: MED-98   Category: Marketing   Time: 2021-03-12T19:22:20.583   By: Jones, Mary

谢谢!

标签: pythonjirajira-rest-apipython-jira

解决方案


推荐阅读