使用jira的api获得project的board参数和sprint参数
需求
每个jira项目都有sprint参数和board参数。关系为一对多的关系。
project:board=1:n
board:sprint=1:n
如果要查询出一个项目有哪些正在进行的sprint,还需要费一番功夫。因为目前jira -api的python库里并没有给出方法,不过我们可以通过下面的方法获得:
通过get请求,根据项目的key或者ID获得board信息,地址和参数如下
url+"/rest/agile/1.0/board?projectKeyOrId=" + projectKeyOrId通过get请求,根据board的ID查询到sprint的信息,根据state进行筛选
url+"/rest/agile/1.0/board/" + str(item['id']) + "/sprint?state=future,active"
代码
# -- coding: UTF-8 --
import requests
from jira import JIRA
url = 'https://jira.atlassian.com'
jira = JIRA(server=url, basic_auth=('username', 'password'))
cookies = jira._session.cookies
projectKeyOrId = "project_key"
board_url = url+"/rest/agile/1.0/board?projectKeyOrId=" + projectKeyOrId
response = requests.get(url, cookies=cookies,
headers={"Accept": "application/json"})
# print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
qq = response.json()
sprint_result_list = []
for item in qq['values']:
sprint_url = url+"/rest/agile/1.0/board/" + str(item['id']) + "/sprint?state=future,active"
response = requests.get(url, cookies=cookies,
headers={"Accept": "application/json"})
sprint_json = response.json()
if 'values' in sprint_json:
sprint_list = sprint_json['values']
for sprint in sprint_list:
element = {'sprint_id': sprint['id'], 'sprint_name': sprint['name']}
if element not in sprint_result_list:
sprint_result_list.append(element)
print(sprint_result_list)