(4) JIRA API docking: Defect Analysis and task analysis
leo_ hou 2021-06-04 10:36:06

        During or after the iteration , We need to reflect the defect details in our test daily report or test report , Even the efficiency of our work . This article discusses how to pass jira api Get defect information and analyze it , At the same time, obtain the required subtasks to understand the test and development man hours .

  The specific code is as follows

 // Define data objects
@Data
public class ReportData {
String name;
int bugNum;
int taskNum;
double taskTime;
String bugTate;
}
/**
* obtain sprint The development task under the environment 、 Test tasks and defects
*
* @param springId
* @return
*/
public static Map<String, Map<String, ReportData>> getReportData(String springId) {
Map<String, Map<String, ReportData>> result = new HashMap<>();
// When there are many defects, we do pagination query , Default one page 150 Data
JSONObject jsonObject = getIssueKey(0, springId);
if (!JSONNull.getInstance().equals(jsonObject)) {
// Parse the query data
Map<String, ReportData> testerData = new HashMap<>();// Test task
Map<String, ReportData> developData = new HashMap<>();// Development tasks
Map<String, ReportData> bugDetail = new HashMap<>();// Defect level
Map<String, ReportData> bugReason = new HashMap<>();// The cause of the defect is
// Parsing data
result = getReportData(jsonObject, testerData, developData, bugDetail, bugReason);
// Gets the total number of defects returned by the interface
int total = jsonObject.getInt("total");
logger.info("spring I have in common story" + total + " individual ");
if (total > 150) {
// If it is greater than 150 Page query is performed
int page = total / 150;
if (total % 150 > 0) {
page = page + 1;// Total page number
}
logger.info("spring I have in common story" + page + " page ");
for (int pageIndex = 1; pageIndex < page; pageIndex++) {
// Paging data
JSONObject object = getIssueKey(pageIndex * 150, springId);
if (!JSONNull.getInstance().equals(object)) {
// Parsing data
result = getReportData(object, result.get("testerGeneral"), result.get("developGeneral"), result.get("bugDetail"), result.get("bugReason"));
}
}
}
}
return result;
}
/**
* obtain spring Under the issue
*
* @param startAt
* @param springId
* @return
*/
private static JSONObject getIssueKey(int startAt, String springId) {
// call jira api Interface acquisition sprint All of them 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) {
// Directly return the query result
JSONObject jsonObject = JSONObject.fromObject(issueResponse.getResponseBody().toString());
return jsonObject;
}
return null;
}
/**
* Parsing data Analyze the situation of testers respectively , Developers , Defect level profile and defect cause profile
*
* @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)) {
// obtain issuetype
JSONObject issuetype = fields.getJSONObject("issuetype");
if (!JSONNull.getInstance().equals(issuetype)) {
// obtain issue Category
String issuetypeName = issuetype.getString("name");
// Get the information of the operator
JSONObject assignee = fields.getJSONObject("assignee");
if (!JSONNull.getInstance().equals(assignee)) {
// Get the name of the operator
String displayName = assignee.getString("displayName");
// Get information about the estimated time to complete the task , This field is a custom field
double originalEstimate = 0;
JSONObject timetracking = fields.getJSONObject("timetracking");
if (!JSONNull.getInstance().equals(timetracking) && timetracking.size() > 0) {
// Get the estimated time
originalEstimate = timetracking.getInt("originalEstimateSeconds") / 3600;
}
// Different processing according to the task category
switch (issuetypeName) {
case "Story":// demand
break;
case "SubTask":// Develop subtasks
setReportData(developData, displayName, originalEstimate, false);
break;
case " Test subtasks ": Test subtasks
setReportData(testerData, displayName, originalEstimate, false);
break;
case " defects ":
// Get the solution
JSONObject resolution = fields.getJSONObject("resolution");
if (!JSONNull.getInstance().equals(resolution)) {
// Filter out the rejected bug
if (" Rejected ".equals(resolution.getString("name"))) {
break;
}
}
setReportData(developData, displayName, 0, true);
// Get reporter information
JSONObject reporter = fields.getJSONObject("reporter");
if (!JSONNull.getInstance().equals(reporter)) {
// Get the name of the reporter
String reporterName = reporter.getString("displayName");
setReportData(testerData, reporterName, 0, true);
}
//bug Classification by grade
JSONObject priority = fields.getJSONObject("priority");
setReportData(bugDetail, priority, "name");
//bug The causes are classified
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;
}
/**
* Unified setting of report information
*
* @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)) {
// If you include key
ReportData temp = reportDataMap.get(key);
if (originalEstimate != 0) {
// Set the task time , In hours
temp.setTaskTime(temp.getTaskTime() + originalEstimate);
}
if (isBug) {
// Number of defects +1
temp.setBugNum(temp.getBugNum() + 1);
} else {
// Number of tasks +1
temp.setTaskNum(temp.getTaskNum() + 1);
}
// Set defect rate
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) {
// Set the task time , In hours
reportData.setTaskTime(originalEstimate);
}
if (isBug) {
// Number of defects +1
reportData.setBugNum(1);
} else {
// Number of tasks +1
reportData.setTaskNum(1);
}
// Set defect rate
String formatNum = decimalFormat
.format((float) reportData.getBugNum()
/ (reportData.getTaskTime() == 0 ? 1 : reportData.getTaskTime()) * 100);
reportData.setBugTate(formatNum + "%");
reportData.setName(key);
reportDataMap.put(key, reportData);
}
}
/**
* Unified setting of report information
*
* @param dataMap
* @param jsonObject
* @param key
*/
private static void setReportData(Map<String, ReportData> dataMap, JSONObject jsonObject, String key) {
if (!JSONNull.getInstance().equals(jsonObject)) {
// obtain key value
String priorityName = jsonObject.getString(key);
if (dataMap.containsKey(priorityName)) {
// Number +1
ReportData reportData = dataMap.get(priorityName);
reportData.setBugNum(reportData.getBugNum() + 1);
} else {
// Number +1
ReportData reportData = new ReportData();
reportData.setBugNum(1);
reportData.setName(priorityName);
dataMap.put(priorityName, reportData);
}
}
}
//getReportData(String sprintId) Method returns an example of the result , according to Map Just read it in your own format
{
bugReason={
Function error =ReportData(name= Function error ,
bugNum=3,
taskNum=0,
taskTime=0.0,
bugTate=null),
Demand question =ReportData(name= Demand question ,
bugNum=1,
taskNum=0,
taskTime=0.0,
bugTate=null)
},
developGeneral={
Sangluo =ReportData(name= Sangluo ,
bugNum=3,
taskNum=7,
taskTime=28.0,
bugTate=10.71%),
White clothes =ReportData(name= White clothes ,
bugNum=0,
taskNum=8,
taskTime=18.0,
bugTate=0.00%),
qingyuan =ReportData(name= qingyuan ,
bugNum=1,
taskNum=0,
taskTime=0.0,
bugTate=100.00%)
},
testerGeneral={
Huangtai =ReportData(name= Huangtai ,
bugNum=4,
taskNum=3,
taskTime=24.0,
bugTate=16.67%)
},
bugDetail={
Medium=ReportData(name=Medium,
bugNum=4,
taskNum=0,
taskTime=0.0,
bugTate=null)
}
}
// The optimized results are displayed as icons as shown in the figure below

 

 

 

 

More articles please pay attention to the official account.

 

Please bring the original link to reprint ,thank
Similar articles

2021-08-09

2021-08-09