· 6 years ago · Apr 05, 2020, 09:30 PM
1 public static Map<String, Boolean> getFileFixed(List<Integer> issuesID, String projectName, Map<String, Boolean> listOfFile, String startDate, String endDate) throws IOException, NoHeadException, GitAPIException, ParseException {
2
3 List<Integer> checkedIssuesID = new ArrayList<>();
4 RevCommit commitBefore = null;
5
6 // Create new FileRepositoryBuilder
7 FileRepositoryBuilder builder = new FileRepositoryBuilder();
8 // Setting the project's folder
9 String repoFolder = System.getProperty("user.dir") + "/" + projectName + "/.git";
10 // Set the project's folder
11 Repository repository = builder.setGitDir(new File(repoFolder)).readEnvironment().findGitDir().build();
12
13 int counter = 0;
14
15 // Try to open the Git repository
16 try (Git git = new Git(repository)) {
17
18 // Get all the commits
19 Iterable<RevCommit> commits = git.log().all().call();
20
21 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
22
23 //convert String to LocalDate
24 LocalDate firstCommit = LocalDate.parse(startDate, formatter);
25 LocalDate lastCommit = LocalDate.parse(endDate, formatter);
26 int monthsDiff = 12*(lastCommit.getYear()-firstCommit.getYear()) + (lastCommit.getMonthValue() - firstCommit.getMonthValue());
27 firstCommit = firstCommit.plusMonths(monthsDiff/2);
28 lastCommit = LocalDate.parse(startDate, formatter);
29 lastCommit = lastCommit.plusMonths((monthsDiff/2) + 1);
30
31 // Iterate over the single commit
32 System.out.println("Start: " + firstCommit.toString());
33 System.out.println("End: " + lastCommit.toString());
34
35 for (RevCommit commit : commits) {
36
37 if (commitBefore != null) {
38
39 // Iterate over the single issues
40 for (Integer issues : issuesID) {
41
42 // Check if commit message contains the issues ID and the issues is labeled like "not checked"
43 LocalDate commitLocalDate = commitBefore.getAuthorIdent().getWhen().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
44
45 if (commitBefore.getFullMessage().contains(projectName+"-"+issues) && !checkedIssuesID.contains(issues) && (commitLocalDate.equals(firstCommit) || (commitLocalDate.isAfter(firstCommit) && commitLocalDate.isBefore(lastCommit)))) {
46 counter = counter + 1;
47
48 try (DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
49 diffFormatter.setRepository(repository);
50 diffFormatter.setContext(0);
51 for (DiffEntry entry : diffFormatter.scan(commit, commitBefore)) {
52 if (entry.getChangeType() == DiffEntry.ChangeType.MODIFY) {
53 listOfFile.replace(entry.getNewPath(), true);
54 }
55 }
56 }
57 checkedIssuesID.add(issues);
58 }
59 }
60 }
61 commitBefore = commit;
62 }
63 }
64 System.out.println("Il numero di commit dell'ultimo mese è: " + counter);
65 return listOfFile;
66}
67
68
69 public static List<Integer> getFII(String projectName) throws IOException, JSONException{
70 ArrayList<Integer> myList = new ArrayList<>();
71 Integer j = 0;
72 Integer i = 0;
73 Integer total = 1;
74
75 //Get JSON API for closed bugs w/ AV in the project
76 do {
77 //Only gets a max of 1000 at a time, so must do this multiple times if bugs >1000
78 j = i + 1000;
79 String url = "https://issues.apache.org/jira/rest/api/2/search?jql=project=%22"
80 + projectName + "%22AND(%22status%22=%22closed%22OR"
81 + "%22status%22=%22resolved%22)AND%22resolution%22=%22fixed%22&fields=key&startAt="
82 + i.toString() + "&maxResults=" + j.toString();
83 JSONObject json = readJsonFromUrl(url);
84 JSONArray issues = json.getJSONArray("issues");
85 total = json.getInt("total");
86 for (; i < total && i < j; i++) {
87 //Iterate through each bug
88 String key = issues.getJSONObject(i%1000).get("key").toString().split("-")[1];
89 myList.add(Integer.parseInt(key));
90 }
91 } while (i < total);
92 return myList;
93 }