如何使用 Python Jira 库获取 Jira 解析 ID?

问题描述 投票:0回答:2

现在我正在尝试获取给定项目的所有结果 ID。我正在使用此处找到的 jira python 库:https://jira.readthedocs.io/ 以及此处文档的较长版本:https://buildmedia.readthedocs.org/media/pdf/jira/latest /jira.pdf

代码如下:

option: {
    'server': url
}

jira_client = JIRA(options, token_auth=token)

response = jira_client.resolutions()
print(response)

这将返回一个包含单个元素的列表,并且该元素是单个字符串,如下所示:

[<JIRA Resolution: name='Done', id='10000'>, <JIRA Resolution: name="Won't Do", id='10001'>, <JIRA Resolution: name='Duplicate', id='10002'>, <JIRA Resolution: name='Declined', id='10003'>, <JIRA Resolution: name='Cancelled', id='10100'>, <JIRA Resolution: name='Transferred', id='10200'>, <JIRA Resolution: name='Known Error', id='10300'>, <JIRA Resolution: name='Hardware failure', id='10301'>, <JIRA Resolution: name='Software failure', id='10302'>] 

我正在尝试解析代码,这样我就可以获取每个条目的解析名称和解析ID,并将其放入字典列表中,但我不知所措。现在我现在有:

r_temp_list = str(resolutions).replace('<','').replace(">", "").replace("JIRA Resolution: ", "")
print(r_temp_list)

[name='Done', id='10000', name="Won't Do", id='10001', name='Duplicate', id='10002', name='Declined', id='10003', name='Cancelled', id='10100', name='Transferred', id='10200', name='Known Error', id='10300', name='Hardware failure', id='10301', name='Software failure', id='10302']

我尝试使用python requests库,并收到了成功的响应,并且可以通过这种方式解析信息。但为了资源和逻辑,我想坚持一种方法谢谢!

python jira
2个回答
0
投票

嘿@outsideyam,您在使用 Jira Cloud 吗? 如果是这样,以下内容将为您提供您想要的:

import requests
from requests.auth import HTTPBasicAuth
import json

url = "https://your-domain.atlassian.net/rest/api/3/resolution"

auth = HTTPBasicAuth("[email protected]", "<api_token>")

headers = {
   "Accept": "application/json"
}

response = requests.request(
   "GET",
   url,
   headers=headers,
   auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, 
separators=(",", ": ")))

输出应如下所示:

[
  {
    "self": "https://your-domain.atlassian.net/rest/api/3/resolution/1",
    "id": "10000",
    "description": "A fix for this issue is checked into the tree and tested.",
    "name": "Fixed"
  },
  {
    "self": "https://your-domain.atlassian.net/rest/api/3/resolution/3",
    "id": "10001",
    "description": "This is what it is supposed to do.",
    "name": "Works as designed"
  }
]

完整的文档在这里 - https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-resolutions/#api-rest-api-3-resolution-get

我有一个项目可能有助于一些 python/Jira 操作 - https://github.com/dren79/JiraScripting_public


0
投票

我遇到了同样的问题并找到了如何正确提取它的方法,请检查:

option: {
  'server': url
}
jira_client = JIRA(options, token_auth=token)

response = jira_client.resolutions()
for r in response:
  print("Resolution name "+r.name, " ID: "+r.id)

分辨率是具有属性 name 和 id 的对象,您可以通过 api 调用访问它

© www.soinside.com 2019 - 2024. All rights reserved.