diff --git a/gdettt/src/main/java/org/compass/gdet/GitHubAPIDemo.java b/gdettt/src/main/java/org/compass/gdet/GitHubAPIDemo.java index b9af41b..0179887 100644 --- a/gdettt/src/main/java/org/compass/gdet/GitHubAPIDemo.java +++ b/gdettt/src/main/java/org/compass/gdet/GitHubAPIDemo.java @@ -29,6 +29,16 @@ public static void main( String[] args ) { for (GHCommit commit : commits) { System.out.print(GithubDataExtractionTool.commitToString(commit)); } + + //Print Commit Comments + System.out.print(startSection); + System.out.println("COMMIT COMMENTS"); + System.out.print(endSection); + List cComments = + GithubDataExtractionTool.getCommitComments(repo); + for(GHCommitComment cComment : cComments) { + System.out.print(GithubDataExtractionTool.commitCommentToString(cComment)); + } //Print Issues System.out.print(startSection); @@ -49,18 +59,17 @@ public static void main( String[] args ) { System.out.printf("User: %-20s Commit Count: %d\n", GithubDataExtractionTool.getGHUserNameWithFallback(user), commitsPerUser.get(user)); - } - - //Print Commit Count Per User - System.out.print(startSection); - System.out.println("PULL-REQUEST-OPENED-COUNT-PER-USER"); - System.out.print(endSection); - Map prPerUser = - GithubDataExtractionTool.getPullRequestCountPerUser(repo, false); - for (GHUser user : prPerUser.keySet()) { - System.out.printf("User: %-20s PR Opened Count: %d\n", - GithubDataExtractionTool.getGHUserNameWithFallback(user), - prPerUser.get(user)); + } + //Print Commit Count Per User + System.out.print(startSection); + System.out.println("PULL-REQUEST-OPENED-COUNT-PER-USER"); + System.out.print(endSection); + Map prPerUser = + GithubDataExtractionTool.getPullRequestCountPerUser(repo, false); + for (GHUser user : prPerUser.keySet()) { + System.out.printf("User: %-20s PR Opened Count: %d\n", + GithubDataExtractionTool.getGHUserNameWithFallback(user), + prPerUser.get(user)); } //Print Commit Count Per User @@ -75,17 +84,6 @@ public static void main( String[] args ) { prMergedPerUser.get(user)); } - System.out.print(startSection); - System.out.println("ISSUE-CREATED-COUNT-PER-USER"); - System.out.print(endSection); - Map issuesOpenedPerUser = - GithubDataExtractionTool.getIssueCountPerUser(repo); - for (GHUser user : issuesOpenedPerUser.keySet()) { - System.out.printf("User: %-20s PR Merged Count: %d\n", - GithubDataExtractionTool.getGHUserNameWithFallback(user), - issuesOpenedPerUser.get(user)); - } - //Print Pull Requests System.out.print(startSection); System.out.println("Pull Requests"); @@ -102,7 +100,6 @@ public static void main( String[] args ) { System.out.print(GithubDataExtractionTool.pullRequestToString(cpr)); } - //Print Pull Request Comments System.out.print(startSection); System.out.println("Pull Request Review Comments"); System.out.print(endSection); @@ -120,7 +117,7 @@ public static void main( String[] args ) { for(GHBranch gb : gbs) { System.out.print(GithubDataExtractionTool.branchToString(gb)); - } + } } } diff --git a/gdettt/src/main/java/org/compass/gdet/GithubDataExtractionTool.java b/gdettt/src/main/java/org/compass/gdet/GithubDataExtractionTool.java index 7885e90..d5fb9f5 100644 --- a/gdettt/src/main/java/org/compass/gdet/GithubDataExtractionTool.java +++ b/gdettt/src/main/java/org/compass/gdet/GithubDataExtractionTool.java @@ -122,7 +122,7 @@ public static List getBranches(GHRepository repo) { */ public static List getCommitComments(GHRepository repo) { - return repo.listCommitComments().asList(); + return repo.listCommitComments().asList(); } /**getPullRequests * This method will try to get a list of pull requests for a given reposito @@ -242,7 +242,57 @@ public static Map getCommitCountPerUser(List commits) } } + /** getCommitCommentCountPerUser + * Gets a list of all users who have committed to the repository along with + * the number of commits they've made. + * + * @params: + * repo - the GHRepository object to get a list of commits from. + * + * @return: + * Map - a map between all users that have committed to the + * repository and the number of commit comments they've made.Returns an empty map + * if an IOException is encountered. + */ + public static Map getCommitCommentCountPerUser(GHRepository repo) { + List commitComments = getCommitComments(repo); + return getCommitCommentCountPerUser(commitComments); + } + /** getCommitCommentCountPerUser + * Gets a list of all users who have committed to the repository along with + * the number of commit comments they've made. + * + * @params: + * commitComments - a list of commits to find the commits counts per user from. + * + * @return: + * Map - a map between all users that have committed to the + * repository and the number of commit comments they've made. Returns an empty map + * if an IOException is encountered. + */ + public static Map getCommitCommentCountPerUser(List commitComments) { + try { + Map map = new WeakHashMap(); + for (GHCommitComment commitComment : commitComments) { + GHUser committer = commitComment.getUser(); + if (map.containsKey(committer)) { + map.put(committer, map.get(committer) + 1); + } + else if(map.containsValue(null)) + { + map.put(committer, 0); + } + else { + map.put(committer, 1); + } + } + return map; + } + catch (IOException e) { + return new WeakHashMap(); + } + } /** getIssueCountPerUser * Generates a mapping between all users who have filed issues with * the repository and the number of issues they've made. @@ -452,6 +502,31 @@ public static String commitToString(GHCommit commit) { response += String.format("%32s\n\n", "").replace(" ", "-"); return response; } + + /**commitsCommentToString + * converts a commitComments to a formatted string representing the commit. + * + * @params: + * commit - a List of commitComments to get a formatted string for. + * + * @return: + * string - a formatted string representation of the commit. + */ + public static String commitCommentToString(GHCommitComment cComment) { + try { + String response = ""; + response += String.format("%32s\n", "").replace(" ", "-"); + response += cComment.getUser().getLogin() + "\n"; + response += "\nCommit Details:\n"; + response += commitToString(cComment.getCommit()); + response += cComment.getBody() + "\n"; + response += String.format("%32s\n\n", "").replace(" ", "-"); + return response; + } + catch (IOException e) { + return ""; + } + } /**pullRequestToString * converts a pull request to a formatted string representing the pull request. * diff --git a/gdettt/src/test/java/org/compass/gdet/GithubDataExtractionToolTest.java b/gdettt/src/test/java/org/compass/gdet/GithubDataExtractionToolTest.java index 83bc3e1..44b4941 100644 --- a/gdettt/src/test/java/org/compass/gdet/GithubDataExtractionToolTest.java +++ b/gdettt/src/test/java/org/compass/gdet/GithubDataExtractionToolTest.java @@ -169,16 +169,17 @@ public void shouldGetAFormattedPullRequestString() { List pr = GithubDataExtractionTool.getPullRequests(repo,GHIssueState.CLOSED); String prString = GithubDataExtractionTool.pullRequestToString(pr.get(pr.size()-1)); String expected = - "----------------------------------------------------------------\n" + - "Initial Project Setup\n" + - "Created By: Taylor\n" + - "Created Date: Wed Nov 07 09:40:32 EST 2018\n" + - "Merged By: Gurney Buchanan\n"+ - "Merged Date:Fri Nov 09 08:39:06 EST 2018\n\n"+ - "Additions: 88\n"+ - "Deletions: 1\n"+ - "Number of Commits: 1\n"+ - "----------------------------------------------------------------\n\n"; + "----------------------------------------------------------------\n"+ + "Initial Project Setup\n"+ + "Created By: Taylor\n"+ + "Created Date: Wed Nov 07 14:40:32 GMT 2018\n" + + "Merged By: Gurney Buchanan\n" + + "Merged Date:Fri Nov 09 13:39:06 GMT 2018\n" + + + "\nAdditions: 88"+ + "\nD0letions: 1" + + "\nNumber of Commits: 1\n" + + "----------------------------------------------------------------\n\n"; assertTrue(expected.equals(prString)); } /*