python - 如何通过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 数据。任何线索都会有所帮助。
解决方案
我对 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'])
推荐阅读
- node.js - 使用设备和浏览器连接到 MQTT 代理
- xml - 在 xml 中使用“本地”命名空间
- javascript - 将状态设置反应到前一个元素的值
- r - 如何在 R Shiny 的 Highcharter 库中将点击事件附加到 hcmap 函数?
- c - 为什么动态 ELF 文件中没有 .rel.dyn/.got.plt 部分?
- linux - 写入内存 - LINUX
- python - 使用来自另一个文件的值从一个文件中读取特定行
- javascript - 使用 javascript 选择 JSTL 标记
- database - 如何使用带有 Redshift 的 COPY 命令列出列?
- java - 编程游戏中的 Java 循环