Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions gdettt/src/main/java/org/compass/gdet/GitHubAPIDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<GHCommitComment> cComments =
GithubDataExtractionTool.getCommitComments(repo);
for(GHCommitComment cComment : cComments) {
System.out.print(GithubDataExtractionTool.commitCommentToString(cComment));
}

//Print Issues
System.out.print(startSection);
Expand All @@ -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<GHUser, Integer> 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<GHUser, Integer> 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
Expand All @@ -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<GHUser, Integer> 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");
Expand All @@ -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);
Expand All @@ -120,7 +117,7 @@ public static void main( String[] args ) {
for(GHBranch gb : gbs)
{
System.out.print(GithubDataExtractionTool.branchToString(gb));
}
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static List<GHBranch> getBranches(GHRepository repo) {
*/
public static List<GHCommitComment> 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
Expand Down Expand Up @@ -242,7 +242,57 @@ public static Map<GHUser, Integer> getCommitCountPerUser(List<GHCommit> 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<GHUser, Integer> - 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<GHUser, Integer> getCommitCommentCountPerUser(GHRepository repo) {
List<GHCommitComment> 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<GHUser, Integer> - 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<GHUser, Integer> getCommitCommentCountPerUser(List<GHCommitComment> commitComments) {
try {
Map<GHUser, Integer> map = new WeakHashMap<GHUser, Integer>();
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<GHUser, Integer>();
}
}
/** getIssueCountPerUser
* Generates a mapping between all users who have filed issues with
* the repository and the number of issues they've made.
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,17 @@ public void shouldGetAFormattedPullRequestString() {
List<GHPullRequest> 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));
}
/*
Expand Down