From 5d3ae060eabd054fa9174c35a4aca51dfa61fd46 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 31 Mar 2017 10:09:00 +0530 Subject: [PATCH] fix changes asked in PR 1 --- org.wso2.codequalitymatrices/pom.xml | 12 +-- .../code/quality/matrices/ApiUtility.java | 12 --- .../code/quality/matrices/Application.java | 2 - .../code/quality/matrices/ChangesFinder.java | 80 +++++++------------ .../matrices/CodeQualityMatricesExecutor.java | 13 +-- .../quality/matrices/GithubApiCaller.java | 22 ++--- .../code/quality/matrices/PmtApiCaller.java | 8 +- .../code/quality/matrices/ReviewAnalyser.java | 43 +++++----- .../quality/matrices/SdkGitHubClient.java | 9 +-- .../quality/matrices/model/Constants.java | 5 +- .../matrices/model/GraphQlResponse.java | 13 +-- .../code/quality/matrices/model/Graphql.java | 1 - .../quality/matrices/model/GraphqlAuthor.java | 12 +-- .../quality/matrices/model/GraphqlBlame.java | 4 +- .../quality/matrices/model/GraphqlCommit.java | 5 ++ .../quality/matrices/model/GraphqlData.java | 3 + .../quality/matrices/model/GraphqlEdge.java | 13 +-- .../matrices/model/GraphqlHistory.java | 13 +-- .../quality/matrices/model/GraphqlNode.java | 3 + .../quality/matrices/model/GraphqlObject.java | 3 + .../quality/matrices/model/GraphqlRange.java | 6 ++ .../matrices/model/GraphqlRepository.java | 13 +-- .../matrices/model/IssueApiResponse.java | 13 +-- .../quality/matrices/model/Repository.java | 13 +-- .../{GraphqlItem.java => RepositoryItem.java} | 6 +- .../matrices/model/ReviewApiResponse.java | 22 ++--- .../code/quality/matrices/model/Reviewer.java | 9 ++- .../matrices/model/SearchApiResponse.java | 22 ++--- .../quality/matrices/model/SearchItem.java | 35 ++++---- 29 files changed, 197 insertions(+), 218 deletions(-) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/{GraphqlItem.java => RepositoryItem.java} (89%) diff --git a/org.wso2.codequalitymatrices/pom.xml b/org.wso2.codequalitymatrices/pom.xml index 11b129e..6639c58 100644 --- a/org.wso2.codequalitymatrices/pom.xml +++ b/org.wso2.codequalitymatrices/pom.xml @@ -20,26 +20,21 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.wso2 wso2 5 - org.wso2.codeQualityMatrices CodeQualityMatrices - 0.0.1-SNAPSHOT + 1.0.0-SNAPSHOT jar - CodeQualityMatrices http://maven.apache.org - 1.8 UTF-8 - junit @@ -67,27 +62,22 @@ org.eclipse.egit.github.core 2.1.5 - org.apache.httpcomponents httpclient 4.5.2 - com.googlecode.json-simple json-simple 1.1.1 - org.apache.commons commons-lang3 3.5 - - diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index 3994bdf..8f999ba 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -41,10 +41,8 @@ public final class ApiUtility { // to prevent instantiation private ApiUtility() { - } - /** * This is used for calling the REST APIs. * @@ -58,11 +56,9 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); String jsonText; - try { httpResponse = httpClient.execute(httpGet); int responseCode = httpResponse.getStatusLine().getStatusCode(); - if (responseCode == 200) { //success bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), @@ -74,8 +70,6 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio } // creating a JSON object from the response jsonText = stringBuilder.toString(); - - } else { throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + responseCode); @@ -123,7 +117,6 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); String jsonText; - try { httpResponse = httpClient.execute(httpPost); int responseCode = httpResponse.getStatusLine().getStatusCode(); @@ -137,13 +130,10 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice } jsonText = stringBuilder.toString(); logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); - } else { throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + responseCode); - } - } catch (UnsupportedEncodingException e) { throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); } catch (ClientProtocolException e) { @@ -174,9 +164,7 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice logger.debug("IOException occurred when closing the HttpClient", e); } } - } - return jsonText; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java index b6cc321..5109bbc 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java @@ -30,11 +30,9 @@ public class Application { public static void main(String[] args) { if (args.length == 3) { - String pmtToken = args[0]; String patchId = args[1]; String gitHubToken = args[2]; - CodeQualityMatricesExecutor codeQualityMatricesExecutor = new CodeQualityMatricesExecutor(pmtToken, patchId, gitHubToken); codeQualityMatricesExecutor.execute(); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index bc4c561..a700000 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -47,7 +47,6 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); - private List fileNames = new ArrayList<>(); private List patchString = new ArrayList<>(); private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed @@ -59,7 +58,6 @@ public class ChangesFinder { private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); - /** * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch * @@ -77,7 +75,6 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List repoLocation.add(recordItem.getRepository().getFull_name())); + searchCommitPojo.getContainingRepositories() + .forEach(recordItem -> repoLocation.add(recordItem.getRepository().getRepositoryLocation())); logger.debug("Repositories having the given commit are successfully saved in an List"); SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); - repoLocation.stream() .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { @@ -122,7 +118,6 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke fileNames = fileNamesWithPatcheString.get("fileNames"); patchString = fileNamesWithPatcheString.get("patchString"); } - saveRelaventEditLineNumbers(fileNames, patchString); try { findFileChanges(repositoryName, commitHash, gitHubToken); @@ -130,8 +125,10 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke logger.debug(e.getMessage(), e.getCause()); } }); - logger.debug("\n Author names :" + authorNames); - logger.debug("\n Author commits :" + authorCommits); + if (logger.isDebugEnabled()) { + logger.debug("\n Author names :" + authorNames); + logger.debug("\n Author commits :" + authorCommits); + } } /** @@ -143,9 +140,9 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke */ private void saveRelaventEditLineNumbers(List fileNames, List patchString) { - //filtering only the line ranges that are modified and saving to a string array - - // cannot use parallel streams here as the order of the line changes must be preserved + /*filtering only the line ranges that are modified and saving to a string array cannot use parallel streams + here as the order of the line changes must be preserved + */ patchString.stream() .map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) .forEach(lineChanges -> { @@ -162,7 +159,6 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa // for taking the parent commit String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter (tempString, "+"); - int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore (lineRangeInTheOldFileBeingModified, ",")); int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter @@ -188,8 +184,10 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa changedLineRanges.add(changedRange); }); logger.debug("done saving file names and their relevant modification line ranges"); - logger.debug("\n File names : " + fileNames); - logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); + if (logger.isDebugEnabled()) { + logger.debug("\n File names : " + fileNames); + logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); + } } /** @@ -206,44 +204,40 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH // filtering the owner and the Repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); String repositoryName = StringUtils.substringAfter(repoLocation, "/"); - // iterating over the fileNames arraylist for the given commit - // cannot use parallel streams here as the order of the file names is important in the process + /* iterating over the fileNames arraylist for the given commit cannot use parallel streams here as the order + of the file names is important in the process + */ fileNames.forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file List lineRangesForSelectedFile = changedLineRanges.get(index); // for storing the parent commit hashes for all the changed line ranges of the relevant file parentCommitHashes = new HashMap<>(); - Graphql graphqlBean = new Graphql(); graphqlBean.setGraphqlInputWithHistory(owner, repositoryName, commitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithHistory()); - String jsonText = null; try { // calling the graphql API for getting blame information for the current file. jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } //reading the above saved output for the current selected file name try { readBlameForSelectedFile(jsonText, lineRangesForSelectedFile); - logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); + if (logger.isDebugEnabled()) { + logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); + } } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } - - findAuthorCommits(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); - logger.debug("Authors and author commits of bug lines of code which are being fixed from the given " + "patch are saved successfully to authorNames and authorCommits Sets"); }); } - /** * This reads the blame received for the current selected file and insert parent commits of the changed lines * to a list. @@ -257,11 +251,9 @@ private void readBlameForSelectedFile(String jsonText, List changedRange GraphQlResponse graphQlResponse; try { graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); } - GraphQlResponse finalGraphQlResponse = graphQlResponse; // to make a effective final variable changedRangesOfSelectedFile.forEach(lineRange -> { int startingLineNo; @@ -275,35 +267,27 @@ private void readBlameForSelectedFile(String jsonText, List changedRange */ startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); - //for storing age with the relevant parent commit hash Map> ageWithParentCommit = new HashMap<>(); - while (endLineNo >= startingLineNo) { int finalStartingLineNo = startingLineNo; // to make a effective final variable - - finalGraphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() + finalGraphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && graphqlRange.getEndingLine() >= finalStartingLineNo)) .forEach(graphqlRange -> { int age = graphqlRange.getAge(); - String url = graphqlRange.getCommit().getHistory().getEdges().get(1).getNode().getUrl(); + String url = graphqlRange.getCommit().getHistory().getCommits().get(1).getDetails() + .getUrl(); /* get(1) is used directly as there are only 2 elements in the List and last resembles the parent commit */ - String parentCommit = StringUtils.substringAfter(url, "commit/"); ageWithParentCommit.putIfAbsent(age, new HashSet<>()); if (!ageWithParentCommit.get(age).contains(parentCommit)) { ageWithParentCommit.get(age).add(parentCommit); } - - }); - - startingLineNo++; // to check for other line numbers - } TreeMap> sortedAgeWithParentCommit = new TreeMap<>(ageWithParentCommit); Set parentCommit = sortedAgeWithParentCommit.get(sortedAgeWithParentCommit.firstKey()); @@ -312,7 +296,6 @@ private void readBlameForSelectedFile(String jsonText, List changedRange }); } - /** * This is used to find the author and author commits of the buggy lines of code which are been fixed by the * given patch. @@ -331,23 +314,21 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN Graphql graphqlBean = new Graphql(); commitHashes.parallelStream() .forEach(commitHash -> { - graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, commitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); - String jsonText = null; try { jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } - saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); }); } - logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been fixed " + - "by the given patch are successfully saved to lists"); - + if (logger.isDebugEnabled()) { + logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been " + + "fixed by the given patch are successfully saved to lists"); + } } /** @@ -361,7 +342,6 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - lineRangesForSelectedFile.forEach(lineRange -> { int startingLineNo; int endLineNo; @@ -371,23 +351,17 @@ private void saveAuthorCommits(String jsonText, String oldRange, List li // need to consider the correct line range in the old file for finding authors and author commits startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - while (endLineNo >= startingLineNo) { int finalStartingLineNo = startingLineNo; // to make a effective final variable - - graphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() + graphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && graphqlRange.getEndingLine() >= finalStartingLineNo)) .forEach(graphqlRange -> { - String authorName = graphqlRange.getCommit().getAuthor().getName(); String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), "commit/"); - authorNames.add(authorName); // authors are added to the Set authorCommits.add(authorcommit); // author commits are added to the set - - }); startingLineNo++; // to check for other line numbers } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java index e63b4f7..704b356 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java @@ -28,7 +28,6 @@ import static com.wso2.code.quality.matrices.model.Constants.COMMITS_INSIDE_GIVEN_PATCH; - /** * This is used for creating executing the program. * @@ -52,7 +51,6 @@ public CodeQualityMatricesExecutor(String pmtToken, String patchId, String gitHu this.pmtToken = pmtToken; this.patchId = patchId; this.gitHubToken = gitHubToken; - } /** @@ -63,13 +61,10 @@ public void execute() { List commitHashes = findCommitHashesInPatch(); ChangesFinder changesFinder = new ChangesFinder(); Set authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitHashes); - ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); reviewAnalyser.findReviewers(authorCommits, gitHubToken); reviewAnalyser.printReviewUsers(); - logger.debug("The application executed successfully"); - } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } @@ -84,15 +79,12 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti PmtApiCaller pmtApiCaller = new PmtApiCaller(); String jsonText; List commitHashes = new ArrayList<>(); - try { jsonText = pmtApiCaller.callApi(pmtToken, patchId); } catch (CodeQualityMatricesException e) { throw new CodeQualityMatricesException("Error occurred while calling PMT API", e); } - Gson gson = new Gson(); - if (jsonText != null) { List pmtResponse = gson.fromJson(jsonText, List.class); for (Object pmtEntry : pmtResponse) { @@ -103,11 +95,12 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti } } } - logger.debug("The commit hashes are: " + commitHashes); + if (logger.isDebugEnabled()) { + logger.debug("The commit hashes are: " + commitHashes); + } } else { throw new CodeQualityMatricesException("The returned jsonText from PMT API is null"); } - return commitHashes; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index d58daa0..2c5cba6 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -25,6 +25,10 @@ import java.io.UnsupportedEncodingException; +import static com.wso2.code.quality.matrices.model.Constants.ACCEPT; +import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.matrices.model.Constants.BEARER; + /** * This is used for all github communications. * @@ -45,9 +49,9 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t String url = "https://api.github.com/search/commits?q=hash%3A" + commitHash; try { httpGet = new HttpGet(url); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); //as the accept header is needed for accessing commit search API which is still in preview mode - httpGet.addHeader("Accept", "application/vnd.github.cloak-preview"); + httpGet.addHeader(ACCEPT, "application/vnd.github.cloak-preview"); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Search Commit API is " + "invalid ", e); @@ -69,8 +73,8 @@ public String callReviewApi(String repoLocation, int pullRequestNumber, String g String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; try { httpGet = new HttpGet(url); - httpGet.addHeader("Accept", "application/vnd.github.black-cat-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(ACCEPT, "application/vnd.github.black-cat-preview+json"); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Review Commit API is " + "invalid ", e); @@ -91,8 +95,8 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; try { httpGet = new HttpGet(url); - httpGet.addHeader("Accept", "application/vnd.github.mercy-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(ACCEPT, "application/vnd.github.mercy-preview+json"); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Search Issue API is " + "invalid ", e); @@ -114,11 +118,10 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken HttpPost httpPost; try { httpPost = new HttpPost(url); - httpPost.addHeader("Authorization", "Bearer " + githubToken); - httpPost.addHeader("Accept", "application/json"); + httpPost.addHeader(AUTHORIZATION, BEARER + githubToken); + httpPost.addHeader(ACCEPT, "application/json"); StringEntity entity = new StringEntity(graphqlJsonStructure.toString()); httpPost.setEntity(entity); - } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Graphql API is " + "invalid", e); @@ -127,6 +130,5 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken "Structure", e); } return ApiUtility.callGraphQlApi(httpPost); - } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java index e95b8ae..799af57 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -20,6 +20,9 @@ import org.apache.http.client.methods.HttpGet; +import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.matrices.model.Constants.BEARER; + /** * This is used for all the WSO2 PMT communications. * @@ -27,7 +30,6 @@ */ public class PmtApiCaller { public PmtApiCaller() { - } /** @@ -44,12 +46,10 @@ public String callApi(String accessToken, String patchId) throws CodeQualityMatr HttpGet httpGet; try { httpGet = new HttpGet(pmtUrl); - httpGet.addHeader("Authorization", "Bearer " + accessToken); - + httpGet.addHeader(AUTHORIZATION, BEARER + accessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the PMT API is invalid ", e); } - return ApiUtility.callApi(httpGet); } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java index 33881ac..09dd11f 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java @@ -30,11 +30,11 @@ import java.util.List; import java.util.Map; import java.util.Set; + import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_API_CLOSED_STATE; import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_APPROVED; import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_COMMENTED; - /** * This class is used to find the reviewers of the buggy lines of code. * @@ -48,10 +48,7 @@ public class ReviewAnalyser { private final Set approvedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests private final Set commentedReviewers = new HashSet<>(); - - //constants for filtering github API responses - private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); @@ -62,15 +59,15 @@ public class ReviewAnalyser { * @param githubToken Github access token for accessing github API */ public void findReviewers(Set authorCommits, String githubToken) { - authorCommits.forEach(commitHash -> { String jsonText; - try { jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); Map> prNoWithRepoName = savePrNumberAndRepoName(jsonText); - logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + - "names are successfully saved in a map."); + if (logger.isDebugEnabled()) { + logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + + "names are successfully saved in a map."); + } saveReviewers(prNoWithRepoName, githubToken); } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); @@ -86,24 +83,21 @@ public void findReviewers(Set authorCommits, String githubToken) { * @throws CodeQualityMatricesException */ private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { - // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { IssueApiResponse issueApiResponse = gson.fromJson(jsonText, IssueApiResponse.class); - - issueApiResponse.getItems().parallelStream() - .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getState())) + issueApiResponse.getIssue().parallelStream() + .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getStateOfThePr())) .filter(searchItem -> StringUtils.contains(searchItem.getRepositoryUrl(), "/wso2/")) .forEach(searchItem -> { String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), "repos/"); - int pullRequestNo = searchItem.getNumber(); + int pullRequestNo = searchItem.getPrNumber(); prNoWithRepoName.putIfAbsent(repositoryName, new HashSet<>()); if (!prNoWithRepoName.get(repositoryName).contains(pullRequestNo)) { prNoWithRepoName.get(repositoryName).add(pullRequestNo); } - }); } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); @@ -121,34 +115,31 @@ private Map> savePrNumberAndRepoName(String jsonText) throw * @param githubToken Github access token for accessing github API */ private void saveReviewers(Map> prNoWithRepoName, String githubToken) { - for (Map.Entry entry : prNoWithRepoName.entrySet()) { String repositoryName = (String) entry.getKey(); Set prNumbers = (Set) entry.getValue(); prNumbers.parallelStream() .forEach(prNumber -> { - try { String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); if (jsonText != null) { List reviews = gson.fromJson(jsonText, List.class); // to filter Approved users reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getState())) + .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getReviewState())) .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who approved the pull requests which introduce bug lines to the " + "code base are successfully saved to approvedReviewers list"); - reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getState())) + .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getReviewState())) .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who commented on the pull requests which introduce bug lines to " + "the code base are successfully saved to approvedReviewers list"); } else { - logger.debug("There are no records of reviews for pull request: " + prNumber + - " on " + repositoryName + " repository"); + if (logger.isDebugEnabled()) { + logger.debug("There are no records of reviews for pull request: " + prNumber + + " on " + repositoryName + " repository"); + } } } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); @@ -161,7 +152,9 @@ private void saveReviewers(Map> prNoWithRepoName, String gi * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base */ public void printReviewUsers() { - logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); - logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); + if (logger.isDebugEnabled()) { + logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); + logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); + } } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index cb2d01a..ac436dc 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -45,7 +45,6 @@ public class SdkGitHubClient { private CommitService commitService = null; private RepositoryService repositoryService = null; - SdkGitHubClient(String githubToken) { gitHubClient = new GitHubClient(); gitHubClient.setOAuth2Token(githubToken); @@ -70,16 +69,16 @@ public Map> getFilesChanged(String repositoryName, String c List filesChanged = repositoryCommit.getFiles(); List tempFileNames = new ArrayList<>(); List tempPatchString = new ArrayList<>(); - // this can be run parallely as patchString of a file will always be in the same index as the file filesChanged.parallelStream() .forEach(commitFile -> { tempFileNames.add(commitFile.getFilename()); tempPatchString.add(commitFile.getPatch()); }); - logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files changed " + - "and their " + - "relevant changed line ranges are added to the arraylists successfully"); + if (logger.isDebugEnabled()) { + logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files" + + " changed and their relevant changed line ranges are added to the arraylists successfully"); + } fileNamesAndPatches.put("fileNames", tempFileNames); fileNamesAndPatches.put("patchString", tempPatchString); logger.debug("Modified file names with their relevant modified line ranges are saved to a map " + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java index e92b4b3..bdedd85 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java @@ -28,6 +28,7 @@ public class Constants { public static final String GITHUB_REVIEW_APPROVED = "APPROVED"; public static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; public static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; - - + public static final String AUTHORIZATION = "Authorization"; + public static final String BEARER = "Bearer "; + public static final String ACCEPT = "Accept"; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java index fc7428e..acc56c8 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphQlResponse { - private GraphqlData data; + @SerializedName("data") + private GraphqlData response; - public GraphqlData getData() { - return data; + public GraphqlData getResponse() { + return response; } - public void setData(GraphqlData data) { - this.data = data; + public void setResponse(GraphqlData response) { + this.response = response; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java index 93b91cc..e7bc9be 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java @@ -30,7 +30,6 @@ public class Graphql implements Serializable { private String graphqlInputWithoutHistory; public Graphql() { - } public String getGraphqlInputWithHistory() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java index fa0be6c..4ed6853 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java @@ -18,12 +18,14 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlAuthor { + @SerializedName("name") private String name; - private String email; public String getName() { return name; @@ -32,12 +34,4 @@ public String getName() { public void setName(String name) { this.name = name; } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java index 3fd4d4d..b5f0237 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java @@ -18,13 +18,15 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlBlame { - + @SerializedName("ranges") private List ranges; public List getRanges() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java index 19d2097..6086e66 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java @@ -18,12 +18,17 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlCommit { + @SerializedName("author") private GraphqlAuthor author; + @SerializedName("history") private GraphqlHistory history; + @SerializedName("url") private String url; public GraphqlAuthor getAuthor() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java index e7ccbb1..26c38d5 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java @@ -18,10 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlData { + @SerializedName("repository") private GraphqlRepository repository; public GraphqlRepository getRepository() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java index 82b858c..edcbfc7 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlEdge { - private GraphqlNode node; + @SerializedName("node") + private GraphqlNode details; - public GraphqlNode getNode() { - return node; + public GraphqlNode getDetails() { + return details; } - public void setNode(GraphqlNode node) { - this.node = node; + public void setDetails(GraphqlNode details) { + this.details = details; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java index e204dd5..a7cfbce 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java @@ -18,19 +18,22 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlHistory { - private List edges; + @SerializedName("edges") + private List commits; - public List getEdges() { - return edges; + public List getCommits() { + return commits; } - public void setEdges(List edges) { - this.edges = edges; + public void setCommits(List commits) { + this.commits = commits; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java index 8e670b6..4b79eed 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java @@ -18,10 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlNode { + @SerializedName("url") private String url; public String getUrl() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java index 197a374..e19b2de 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java @@ -18,10 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlObject { + @SerializedName("blame") private GraphqlBlame blame; public GraphqlBlame getBlame() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java index 62c91a1..727c9fa 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java @@ -18,13 +18,19 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlRange { + @SerializedName("startingLine") private int startingLine; + @SerializedName("endingLine") private int endingLine; + @SerializedName("age") private int age; + @SerializedName("commit") private GraphqlCommit commit; public int getStartingLine() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java index 38d1bce..fb2e4ee 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlRepository { - private GraphqlObject object; + @SerializedName("object") + private GraphqlObject file; - public GraphqlObject getObject() { - return object; + public GraphqlObject getFile() { + return file; } - public void setObject(GraphqlObject object) { - this.object = object; + public void setFile(GraphqlObject file) { + this.file = file; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java index 1ca498e..ad9c981 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java @@ -18,19 +18,22 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github REST API */ public class IssueApiResponse { - private List items; + @SerializedName("items") + private List issue; - public List getItems() { - return items; + public List getIssue() { + return issue; } - public void setItems(List items) { - this.items = items; + public void setIssue(List issue) { + this.issue = issue; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java index 2808873..64bd9e0 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class Repository { - private String full_name; + @SerializedName("full_name") + private String repositoryLocation; - public String getFull_name() { - return full_name; + public String getRepositoryLocation() { + return repositoryLocation; } - public void setFull_name(String full_name) { - this.full_name = full_name; + public void setRepositoryLocation(String repositoryLocation) { + this.repositoryLocation = repositoryLocation; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java similarity index 89% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java index 8aa1bb5..332ccfe 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java @@ -18,11 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ -public class GraphqlItem { - +public class RepositoryItem { + @SerializedName("repository") private Repository repository; public Repository getRepository() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java index 6622772..7da25a0 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java @@ -18,26 +18,30 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class ReviewApiResponse { - private String state; - private Reviewer user; + @SerializedName("state") + private String reviewState; + @SerializedName("user") + private Reviewer reviewer; - public String getState() { - return state; + public String getReviewState() { + return reviewState; } - public void setState(String state) { - this.state = state; + public void setReviewState(String reviewState) { + this.reviewState = reviewState; } public Reviewer getReviewer() { - return user; + return reviewer; } - public void setUser(Reviewer user) { - this.user = user; + public void setReviewer(Reviewer reviewer) { + this.reviewer = reviewer; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java index c31568b..862e4ba 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class Reviewer { - private String login; + @SerializedName("login") + private String name; public String getName() { - return login; + return name; } public void setReviewer(String login) { - this.login = login; + this.name = login; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java index 7f254e6..503a2de 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java @@ -18,28 +18,22 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github REST API */ public class SearchApiResponse { - private int total_count; - private List items; - - public int getTotal_count() { - return total_count; - } - - public void setTotal_count(int total_count) { - this.total_count = total_count; - } + @SerializedName("items") + private List containingRepositories; - public List getItems() { - return items; + public List getContainingRepositories() { + return containingRepositories; } - public void setItems(List items) { - this.items = items; + public void setContainingRepositories(List containingRepositories) { + this.containingRepositories = containingRepositories; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java index ce31b93..86fa5e5 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java @@ -18,35 +18,40 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class SearchItem { - private String state; - private int number; - private String repository_url; - - public String getState() { - return state; + @SerializedName("state") + private String stateOfThePr; + @SerializedName("number") + private int prNumber; + @SerializedName("repository_url") + private String repositoryUrl; + + public String getStateOfThePr() { + return stateOfThePr; } - public void setState(String state) { - this.state = state; + public void setStateOfThePr(String stateOfThePr) { + this.stateOfThePr = stateOfThePr; } - public int getNumber() { - return number; + public int getPrNumber() { + return prNumber; } - public void setNumber(int number) { - this.number = number; + public void setPrNumber(int prNumber) { + this.prNumber = prNumber; } public String getRepositoryUrl() { - return repository_url; + return repositoryUrl; } - public void setRepositoryUrl(String repository_url) { - this.repository_url = repository_url; + public void setRepositoryUrl(String repositoryUrl) { + this.repositoryUrl = repositoryUrl; } }