· 5 years ago · May 27, 2020, 11:32 AM
1 public static void getBuggyVersionAVTicket(String projectName) throws IOException, JSONException {
2
3 Integer j = 0;
4 Integer i = 0;
5 Integer total = 1;
6 String key = null;
7
8 // Get JSON API for closed bugs w/ AV in the project
9 do {
10 // Only gets a max of 1000 at a time, so must do this multiple times if bugs
11 // >1000
12 j = i + 1000;
13 String url = "https://issues.apache.org/jira/rest/api/2/search?jql=project=%22" + projectName
14 + "%22AND(%22status%22=%22closed%22OR"
15 + "%22status%22=%22resolved%22)AND%22resolution%22=%22fixed%22&fields=key,versions,resolutiondate,created,fixVersions&startAt="
16 + i.toString() + "&maxResults=1000";
17 JSONObject json = JSONUtils.readJsonFromUrl(url);
18 JSONArray issues = json.getJSONArray("issues");
19 total = json.getInt("total");
20
21 // For each closed ticket...
22 for (; i < total && i < j; i++) {
23
24 JSONObject singleJsonObject = (JSONObject) issues.getJSONObject(i % 1000).get("fields");
25
26 // ... get the key of the ticket,
27 key = issues.getJSONObject(i % 1000).get("key").toString();
28
29 // , get JSONArray associated to the affected versions,
30 JSONArray affectedVersionArray = singleJsonObject.getJSONArray("versions");
31
32 ticketList.add(Integer.valueOf(key.split("-")[1]));
33
34 // Get a Java List from the JSONArray
35 List<String> affectedVersionList = jiraUtilsIstance.getJsonAffectedVersionList(affectedVersionArray);
36
37 // Calculate the AV index of the ticket [IV, FV)
38 jiraUtilsIstance.getBuggyVersionListAV(affectedVersionList, singleJsonObject.getString("resolutiondate").split("T")[0],
39 singleJsonObject.getString("created").split("T")[0], Integer.parseInt(key.split("-")[1]));
40
41 }
42 } while (i < total);
43
44 }