0

我正在尝试建立一个集成,允许我们使用 Zapier 每天报告当前 sprint 的问题、子任务和每个任务的状态。

理想情况下,我会运行一些循环遍历 JIRA 响应的 python,我返回以返回带有名称、状态的问题列表,但如果问题的问题类型为name:"Sub-task".

我打的两个电话是:

  1. 获得积极的冲刺

https://company.atlassian.net/rest/agile/1.0/board/51/sprint?state=active

  1. 在 sprint 中解决问题

https://company.atlassian.net/rest/agile/1.0/sprint/<value_from_above>/issue?fields=key,status,summary,issuetype&maxResults=200

这给出了所有票证的 JSON 输出,格式如下:

{
    expand: "schema,names",
    startAt: 0,
    maxResults: 200,
    total: 97,
    issues: [
        {
            expand: "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            id: "43685",
            self: "https://company.atlassian.net/rest/agile/1.0/issue/43685",
            key: "ENG-431",
            fields: {
                summary: "Summary",
                issuetype: {
                    self: "https://company.atlassian.net/rest/api/2/issuetype/4",
                    id: "4",
                    description: "An improvement or enhancement to an existing feature or task.",
                    iconUrl: "https://company.atlassian.net/secure/viewavatar?size=medium&avatarId=10610&avatarType=issuetype",
                    name: "Improvement",
                    subtask: false,
                    avatarId: 10610
                },
                status: {
                    self: "https://company.atlassian.net/rest/api/2/status/10010",
                    description: "",
                    iconUrl: "https://company.atlassian.net/images/icons/statuses/closed.png",
                    name: "Done",
                    id: "10010",
                    statusCategory: {
                        self: "https://company.atlassian.net/rest/api/2/statuscategory/3",
                        id: 3,
                        key: "done",
                        colorName: "green",
                        name: "Done"
                    }
                }
            }
        },
        {
            expand: "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            id: "45729",
            self: "https://company.atlassian.net/rest/agile/1.0/issue/45729",
            key: "ENG-636",
            fields: {
                summary: "Summary",
                issuetype: {
                    self: "https://company.atlassian.net/rest/api/2/issuetype/5",
                    id: "5",
                    description: "The sub-task of the issue",
                    iconUrl: "https://company.atlassian.net/secure/viewavatar?size=medium&avatarId=10616&avatarType=issuetype",
                    name: "Sub-task",
                    subtask: true,
                    avatarId: 10616
                },
                status: {
                    self: "https://company.atlassian.net/rest/api/2/status/10010",
                    description: "",
                    iconUrl: "https://company.atlassian.net/images/icons/statuses/closed.png",
                    name: "Done",
                    id: "10010",
                    statusCategory: {
                        self: "https://company.atlassian.net/rest/api/2/statuscategory/3",
                        id: 3,
                        key: "done",
                        colorName: "green",
                        name: "Done"
                    }
                }
            }
        },
        {
            expand: "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            id: "45727",
            self: "https://company.atlassian.net/rest/agile/1.0/issue/45727",
            key: "ENG-634",
            fields: {
                summary: "Summary",
                issuetype: {
                    self: "https://company.atlassian.net/rest/api/2/issuetype/1",
                    id: "1",
                    description: "A problem which impairs or prevents the functions of the product.",
                    iconUrl: "https://company.atlassian.net/secure/viewavatar?size=medium&avatarId=10603&avatarType=issuetype",
                    name: "Bug",
                    subtask: false,
                    avatarId: 10603
                },
                status: {
                    self: "https://company.atlassian.net/rest/api/2/status/10010",
                    description: "",
                    iconUrl: "https://company.atlassian.net/images/icons/statuses/closed.png",
                    name: "Done",
                    id: "10010",
                    statusCategory: {
                        self: "https://company.atlassian.net/rest/api/2/statuscategory/3",
                        id: 3,
                        key: "done",
                        colorName: "green",
                        name: "Done"
                    }
                }
            }
        }
    ]
}

理想情况下,它会显示如下:

"Issue 1" | Issue type | To do

"Issue 2" | Issue type | In Progress

"Issue 3" | Issue type | Done

"Issue 4" | Issue type | In Progress

任何想法都非常感谢,谢谢!


更新:

我正在以这种格式(https://i.imgur.com/MEOTGxL.png)从 Zapier 接收数据,所以我想知道是否应该在一次 Python 代码执行中进行这些调用,并将结果解析为给出上面列出的输出。

4

1 回答 1

0
import json
json_data = 'your_json_data'
d = json.loads(json_data)
for i, issue in enumerate(d['issues']):
    print("issue "+str(i)+' | '+ issue['fields']['issuetype']['name'] + ' | ' + issue['fields']['status']['name'])
于 2019-08-14T18:50:15.773 回答