首页 > 解决方案 > 如何通过python获取jira中问题的拉取请求状态

问题描述

我无法理解如何通过 Python jira API 获取拉取请求的状态。我浏览了https://jira.readthedocs.io/en/latest/examples.html,并在互联网上搜索它。但是我无法将 jira 问题与拉取请求相关联,我看到拉取请求与 jira 问题 ID 相关联,但无法理解如何实现它。

我正在使用 python 3.7

from jira import JIRA
issue = auth_jira.issue('XYZ-000')
pull_request = issue.id.pullrequest

我收到此错误:

AttributeError: 'str' object has no attribute 'pullrequest'

我不确定如何在 jira 中访问 pullrequest 数据。任何线索都会有所帮助。

标签: pythonpython-3.xjirajira-rest-apipython-jira

解决方案


我对 jira-API 的另一个 python 包装器做了类似的事情:atlassian-python-api
看看它是否适用于您的情况:

from atlassian import Jira
from pprint import pprint
import json

jira = Jira(
    url='https://your.jira.url',
    username=user,
    password=pwd)

issue = jira.get_issue(issue_key)

# get the custom field ref of the "Development" field (I don't know if it's always the same): 
dev_field_string = issue["fields"]["customfield_13900"]

# the value of this field is a huge string containing a json, that we must parse ourselves:
json_str = dev_field_string.split("devSummaryJson=")[1][:-1]

# we load it with the json module (this ensures json is converted as dict, i.e. 'true' is interpreted as 'True'...)
devSummaryJson = json.loads(json_str)

# the value of interest are under cachedValue/summary:
dev_field_dic = devSummaryJson["cachedValue"]["summary"]
pprint(dev_field_dic)

# you can now access the status of your pull requests (actually only the last one):
print(dev_field_dic['pullrequest']['overall']['state'])

推荐阅读