Jira Api对接实战(四):缺陷分析与任务管理的深度解析

迭代进行期间或者结束后,在我们的测试日报或者测试报告中需要体现缺陷详细情况,甚至大家工作效率情况。本文就讨论下如何通过jira api获取缺陷信息并进行分析,同时获取需求子任务情况来了解测试和开发的工时。

具体代码如下

//定义数据对象
@Data
public class ReportData {

String name;

int bugNum;

int taskNum;

double taskTime;

String bugTate;
}
/**
* 获取sprint下的开发任务、测试任务以及缺陷
*
* @param springId
* @return
*/
public static Map<String, Map<String, ReportData>> getReportData(String springId) {

Map<String, Map<String, ReportData>> result = new HashMap<>();
//缺陷比较多时我们进行分页查询,默认一页150条数据
JSONObject jsonObject = getIssueKey(0, springId);
if (!JSONNull.getInstance().equals(jsonObject)) {

//解析查询的数据
Map<String, ReportData> testerData = new HashMap<>();//测试任务
Map<String, ReportData> developData = new HashMap<>();//开发任务
Map<String, ReportData> bugDetail = new HashMap<>();//缺陷等级
Map<String, ReportData> bugReason = new HashMap<>();//缺陷原因
//解析数据
result = getReportData(jsonObject, testerData, developData, bugDetail, bugReason);
//获取接口返回的缺陷总数
int total = jsonObject.getInt("total");
logger.info("spring上共有story" + total + "个");
if (total > 150) {
//如果大于150则进行分页查询
int page = total / 150;
if (total % 150 > 0) {
page = page + 1;//总页码
}
logger.info("spring上共有story" + page + "页");
for (int pageIndex = 1; pageIndex < page; pageIndex++) {

//分页获取数据
JSONObject object = getIssueKey(pageIndex * 150, springId);
if (!JSONNull.getInstance().equals(object)) {

//解析数据
result = getReportData(object, result.get("testerGeneral"), result.get("developGeneral"), result.get("bugDetail"), result.get("bugReason"));
}
}
}
}
return result;
}
/**
* 获取spring下的issue
*
* @param startAt
* @param springId
* @return
*/
private static JSONObject getIssueKey(int startAt, String springId) {
//调用jira api接口获取sprint下所有issue
HttpClientResponse issueResponse = httpClient("get", "http://you jira address:port/rest/agile/1.0/sprint/" + springId + "/issue?maxResults=150&startAt=" + startAt, "");
if (issueResponse != null && "200".equals(issueResponse.getStateCode())
&& issueResponse.getResponseBody() != null) {
//直接返回查询结果
JSONObject jsonObject = JSONObject.fromObject(issueResponse.getResponseBody().toString());
return jsonObject;
}

return null;
}

/**
* 解析数据 分别解析出测试人员情况,开发人员情况,缺陷等级概况以及缺陷原因概况
*
* @param jsonObject
* @param testerData
* @param developData
* @param bugDetail
* @param bugReason
* @return
*/
private static Map<String, Map<String, ReportData>> getReportData(JSONObject jsonObject, Map<String, ReportData> testerData, Map<String, ReportData> developData, Map<String, ReportData> bugDetail, Map<String, ReportData> bugReason) {

Map<String, Map<String, ReportData>> result = new HashMap<>();
JSONArray issueArray = jsonObject.getJSONArray("issues");
if (issueArray != null && issueArray.size() > 0) {
for (int i = 0; i < issueArray.size(); i++) {

JSONObject issueObject = issueArray.getJSONObject(i);
JSONObject fields = issueObject.getJSONObject("fields");
if (!JSONNull.getInstance().equals(fields)) {
//获取issuetype
JSONObject issuetype = fields.getJSONObject("issuetype");
if (!JSONNull.getInstance().equals(issuetype)) {
//获取issue 类别
String issuetypeName = issuetype.getString("name");
//获取经办人信息
JSONObject assignee = fields.getJSONObject("assignee");
if (!JSONNull.getInstance().equals(assignee)) {
//获取经办人花名
String displayName = assignee.getString("displayName");
//获取完成任务的预估时间的信息,这个字段是自定义字段
double originalEstimate = 0;
JSONObject timetracking = fields.getJSONObject("timetracking");
if (!JSONNull.getInstance().equals(timetracking) && timetracking.size() > 0) {
//获取预估时间
originalEstimate = timetracking.getInt("originalEstimateSeconds") / 3600;
}
//根据任务类别进行不同的处理
switch (issuetypeName) {
case "Story"://需求
break;
case "SubTask"://开发子任务
setReportData(developData, displayName, originalEstimate, false);
break;
case "测试子任务":测试子任务
setReportData(testerData, displayName, originalEstimate, false);
break;
case "缺陷":
//获取解决结果
JSONObject resolution = fields.getJSONObject("resolution");
if (!JSONNull.getInstance().equals(resolution)) {
//过滤掉被否决的bug
if ("被否决".equals(resolution.getString("name"))) {
break;
}
}
setReportData(developData, displayName, 0, true);
//获取报告人信息
JSONObject reporter = fields.getJSONObject("reporter");
if (!JSONNull.getInstance().equals(reporter)) {
//获取报告人花名
String reporterName = reporter.getString("displayName");
setReportData(testerData, reporterName, 0, true);
}
//bug等级进行分类
JSONObject priority = fields.getJSONObject("priority");
setReportData(bugDetail, priority, "name");
//bug原因进行分类
JSONObject reason = fields.getJSONObject("customfield_11522");
setReportData(bugReason, reason, "value");
default:
break;
}
}
}
}
}
}

result.put("testerGeneral", testerData);
result.put("developGeneral", developData);
result.put("bugDetail", bugDetail);
result.put("bugReason", bugReason);
return result;
}
/**
* 统一设置报告信息
*
* @param reportDataMap
* @param key
* @param originalEstimate
* @param isBug
*/
private static void setReportData(Map<String, ReportData> reportDataMap, String key, double originalEstimate, boolean isBug) {

DecimalFormat decimalFormat = new DecimalFormat("0.00");
if (reportDataMap.containsKey(key)) {
//如果包含key
ReportData temp = reportDataMap.get(key);
if (originalEstimate != 0) {
//设置任务时间,以小时计算
temp.setTaskTime(temp.getTaskTime() + originalEstimate);
}
if (isBug) {
//缺陷数量+1
temp.setBugNum(temp.getBugNum() + 1);
} else {
//任务数量+1
temp.setTaskNum(temp.getTaskNum() + 1);
}
//设置缺陷率
String formatNum = decimalFormat
.format((float) temp.getBugNum()
/ (temp.getTaskTime() == 0 ? 1 : temp.getTaskTime()) * 100);
temp.setBugTate(formatNum + "%");
} else {
ReportData reportData = new ReportData();
if (originalEstimate != 0) {
//设置任务时间,以小时计算
reportData.setTaskTime(originalEstimate);
}
if (isBug) {
//缺陷数量+1
reportData.setBugNum(1);
} else {
//任务数量+1
reportData.setTaskNum(1);
}
//设置缺陷率
String formatNum = decimalFormat
.format((float) reportData.getBugNum()
/ (reportData.getTaskTime() == 0 ? 1 : reportData.getTaskTime()) * 100);
reportData.setBugTate(formatNum + "%");
reportData.setName(key);
reportDataMap.put(key, reportData);
}
}

/**
* 统一设置报告信息
*
* @param dataMap
* @param jsonObject
* @param key
*/
private static void setReportData(Map<String, ReportData> dataMap, JSONObject jsonObject, String key) {

if (!JSONNull.getInstance().equals(jsonObject)) {
//获取key值
String priorityName = jsonObject.getString(key);
if (dataMap.containsKey(priorityName)) {
//数量+1
ReportData reportData = dataMap.get(priorityName);
reportData.setBugNum(reportData.getBugNum() + 1);
} else {
//数量+1
ReportData reportData = new ReportData();
reportData.setBugNum(1);
reportData.setName(priorityName);
dataMap.put(priorityName, reportData);
}
}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
//getReportData(String sprintId) 方法返回结果示例,按照Map读取成自己的格式就可以了
{
bugReason={
功能错误=ReportData(name=功能错误,
bugNum=3,
taskNum=0,
taskTime=0.0,
bugTate=null),
需求问题=ReportData(name=需求问题,
bugNum=1,
taskNum=0,
taskTime=0.0,
bugTate=null)
},
developGeneral={
桑落=ReportData(name=桑落,
bugNum=3,
taskNum=7,
taskTime=28.0,
bugTate=10.71%),
白衣=ReportData(name=白衣,
bugNum=0,
taskNum=8,
taskTime=18.0,
bugTate=0.00%),
清远=ReportData(name=清远,
bugNum=1,
taskNum=0,
taskTime=0.0,
bugTate=100.00%)
},
testerGeneral={
黄台=ReportData(name=黄台,
bugNum=4,
taskNum=3,
taskTime=24.0,
bugTate=16.67%)
},
bugDetail={
Medium=ReportData(name=Medium,
bugNum=4,
taskNum=0,
taskTime=0.0,
bugTate=null)
}
}
//对结果优化后以图标显示如下图
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.

(四)Jira Api对接:缺陷分析和任务分析_workflow(四)Jira Api对接:缺陷分析和任务分析_jira_02

(四)Jira Api对接:缺陷分析和任务分析_json_03



QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空