提问人:Oliver T. 提问时间:11/13/2023 最后编辑:Brian Tompsett - 汤莱恩Oliver T. 更新时间:11/14/2023 访问量:37
通过 API 从 Jira 导出筛选结果
Export Filter Result from Jira via API
问:
我正在使用 Python 3.11.5,我正在尝试从 Jira 导入信息以进行编辑。具体来说,我有一个 Jira 过滤器,它给了我大约 1000 个结果:
Key Priority Status Fix Version/s Created Resolution
Key 1 Prio 1 Closed Version 1 04/Jan/22 Done
Key 2 Prio 2 Done … … Wont’t Do
…
Key 1000 … … … … …
有没有办法以更高性能的方式从筛选器调用导入数据?我已经 https://atlassian-python-api.readthedocs.io/jira.html#get-issues-from-jql-search-result-with-all-related-fields 方法
# Export Issues to csv
jira.csv(jql, all_fields=False)
发现。但我不知道我是否必须实施它们。
有没有人对如何以高性能方式导入数据有提示?
我已经尝试过导入数据。但是,使用这种方法,我必须单独导入表的每个日期。总共大约有 6000 个查询,会影响性能。via jira.jql() / jira.issue_field_value()
下面是我如何实现导入 KEY、优先级和状态信息的代码片段:
from atlassian import Jira # To get acces to Jira
import json # Used to convert lists to strings
import pandas as pd # Used to modify table calculations
from datetime import date, datetime
jira = Jira(
url="https://jira.xxx.de/",
username='xxx',
token = "xxx")
def import_raw_data(jql_request):
# Import defect keys from Jira
keys = get_issue_key_list(jql_request)
# Create dataframe for raw data
df = pd.DataFrame(keys, columns = ["Issue_key"])
# Create lists for relevant data
priority = get_jira_value(df["Issue_key"], "priority", df)
status = get_jira_value(df["Issue_key"], "status", df)
# Append data to created data frame
df["Priority"] = pd.DataFrame(priority)
df["Status"] = pd.DataFrame(status)
return df
# Import a list of relevant IDs from Jira
def get_issue_key_list(jql_request):
data = jira.jql(jql_request)
# Convert into string
data = json.dumps(data, indent=4)
# Split string into parts to get all rows with issueKey
data = data.split(",\n")
data = [s for s in data if "issueKey\":" in s]
#print(data,"\n")
# Split string into parts to get all parts witch contains "TCSS-"
data = json.dumps(data)
#print(data,"\n")
data = data.split("\\\"")
#print(data,"\n")
data = [s for s in data if "TCSS-" in s]
#df = pd.DataFrame(data, columns = ["Issue_key"])
return data
# Calculate values from Jira (except fix version and release date)
def get_jira_value(issue_key, aspect, df):
# Import information
data_list = []
for i in issue_key:
raw_data=jira.issue_field_value(i, aspect)
# Convert into string
data=json.dumps(raw_data)
# Split string into parts
data = data.split(", ")
# Get all fix versions (none, one ore more then one are possible)
data = [s for s in data if "name" in s]
# Remove everything but relevant aspect
for x in data:
x = x.replace('"',"")
x = x.replace("name: ","")
x = x.replace('}',"")
value = x
data_list.append(x)
return data_list
df = import_raw_data("filter=33501")
print (df)
结果:
Issue_key Priority Status
0 TCSS-13779 Medium Closed
1 TCSS-11464 Medium Done
2 TCSS-1602 Medium Closed
答: 暂无答案
评论