如何通过python获取jira中问题的pull请求的状态

2024-05-14 15:54:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法理解如何通过pythonjiraapi获取pull请求的状态。 我经历了https://jira.readthedocs.io/en/latest/examples.html, 并在互联网上搜索。但我无法将jira问题与pull请求链接,我看到pull请求链接到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数据。 任何线索都会有帮助


Tags: httpsioid链接状态readthedocsjiraissue
1条回答
网友
1楼 · 发布于 2024-05-14 15:54:09

我对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'])

相关问题 更多 >

    热门问题