【问题标题】:List issues from JIRA using Python使用 Python 列出来自 JIRA 的问题
【发布时间】:2019-12-21 08:13:34
【问题描述】:

我正在尝试建立一个集成,使我们能够使用 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

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


更新:

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

【问题讨论】:

  • 使用python有必要吗?您还可以使用 JQL 使用“project = MyProject AND Sprint in openSprints()”之类的过滤器来获得此结果,然后只显示您需要的 JIRA 字段列(Key | IssueType | Status)。这也将消除您的听众的 Python 知识水平的问题。有关详细信息,请参阅Atlassian documentation。
  • 这份报告的输出是什么?这绝对可以做到,但是这些信息是如何被消耗的呢?通过电子邮件发送电子表格、BI 工具、电子邮件正文等?

标签: python jira zapier sprint


【解决方案1】:
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'])

【讨论】:

  • @KlausD。你想让我使用f"issue {i} | {issue['fields']['issuetype']['name']} | {issue['fields']['status']['name']}" 吗?保持简单,不知道观众对 python 的理解程度。
  • 观众对python的水平是大大的0。
  • @Poojan 不幸的是,我从 Zapier 收到的回复被破坏了,这很遗憾,我想知道我是否能够在代码中进行这些调用并以这种格式打印结果...i.imgur.com/MEOTGxL.png
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-08
  • 1970-01-01
  • 2018-12-30
相关资源
最近更新 更多