diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index ab6a5cd..8bf0441 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -182,7 +182,7 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList { - //@@ -22,7 +22,7 @@ + //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 String tempString = lineChanges[j]; String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter(tempString, "+"); // for taking the parent commit @@ -230,23 +230,22 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin .forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file - ArrayList arrayListOfRelevantChangedLines = lineRangesChanged.get(index); + ArrayList arrayListOfRelevantChangedLinesOfSelectedFile = lineRangesChanged.get(index); commitHashesMapOfTheParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { - // calling the graphql API for getting blame information for the current file and saving it in a location. + // calling the graphql API for getting blame information for the current file. rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression System.exit(1); } // reading the above saved output for the current selected file name - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false, null); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLinesOfSelectedFile, false, null); + logger.info("Parent Commits hashes of the lines which are being fixed by the patch in file " + fileName + " are saved to commitHashesMapOfTheParent map successfully "); - // parent commit hashes are stored in the arraylist for the given file - - iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); + iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLinesOfSelectedFile, gitHubToken); logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); }); } @@ -255,11 +254,11 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin * Reading the blame received for a current selected file name and insert the parent commits of the changed lines, * relevant authors and the relevant commits hashes to look for the reviewers of those line ranges * - * @param rootJsonObject JSONObject containing blame information for current selected file - * @param arrayListOfRelevantChangedLines arraylist containing the changed line ranges of the current selected file - * @param gettingPr should be true if running this method for finding the authors of buggy lines which are being fixed from the patch + * @param rootJsonObject JSONObject containing blame information for current selected file + * @param arrayListOfRelevantChangedLinesOfSelectedFile arraylist containing the changed line ranges of the current selected file + * @param gettingPr should be true if running this method for finding the authors of buggy lines which are being fixed from the patch */ - public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, boolean gettingPr, String oldRange) { + public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, boolean gettingPr, String oldRange) { //running a iterator for fileName arrayList to get the location of the above saved file JSONObject dataJSONObject = (JSONObject) rootJsonObject.get(GITHUB_GRAPHQL_API_DATA_KEY_STRING); @@ -270,7 +269,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList { int startingLineNo = 0; int endLineNo = 0; @@ -286,15 +285,14 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList> mapForStoringAgeAndIndex = new HashMap>(); - //checking line by line by iterating the startinLineNo + //checking line by line by iterating the startingLineNo while (endLineNo >= startingLineNo) { // since the index value is required for later processing, without Java 8 features "for loop" is used for iteration for (int i = 0; i < rangeJSONArray.length(); i++) { @@ -338,7 +336,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList> treeMap = new TreeMap<>(mapForStoringAgeAndIndex); int minimumKeyOfMapForStoringAgeAndIndex = treeMap.firstKey(); // getting the minimum key - //getting the relevant JSONObject indexes which consists of the recent commit with in the relevant line range + //getting the relevant JSONObject indexes which consists of the recent change with in the relevant line range ArrayList indexesOfJsonObjectForRecentCommit = mapForStoringAgeAndIndex.get(minimumKeyOfMapForStoringAgeAndIndex); // the order of the indexesOfJsonObjectForRecentCommit is not important as we only need to get the parent commit hashes indexesOfJsonObjectForRecentCommit.parallelStream() @@ -359,7 +357,6 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, String gitHubToken) { - + public void iterateOverToFindAuthors(String owner, String repositoryName, String fileName, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, String gitHubToken) { for (Map.Entry m : commitHashesMapOfTheParent.entrySet()) { String oldRange = (String) m.getKey(); @@ -388,29 +384,13 @@ public void iterateOverToFindAuthors(String owner, String repositoryName, String JSONObject rootJsonObject = null; try { rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true, oldRange); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLinesOfSelectedFile, true, oldRange); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); System.exit(1); } }); - } - - // calling the graphql api to get the blame details of the current file for the parent commits (That is found by filtering in the graqhQL output) - //as the order is not important in here parallel streams are used -// commitHashesOfTheParent.parallelStream() -// .forEach(parentCommitHashForCallingGraphQl -> { -// graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); -// JSONObject rootJsonObject = null; -// try { -// rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); -// readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); -// } catch (CodeQualityMatricesException e) { -// logger.error(e.getMessage(), e.getCause()); -// System.exit(1); -// } -// }); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index 8e89fee..c42ea4b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -143,9 +143,7 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) for (Map.Entry m : mapContainingPRNoAgainstRepoName.entrySet()) { String productLocation = (String) m.getKey(); - Set prNumbers = (Set) m.getValue(); - prNumbers.stream() .forEach(prNumber -> { setPullRequestReviewAPIUrl(productLocation, prNumber); @@ -175,15 +173,22 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocation, int prNumber) { if (reviewJsonArray.length() != 0) { - for (Object object : reviewJsonArray) { - if (object instanceof JSONObject) { - JSONObject reviewJsonObject = (JSONObject) object; + Pmt.arrayToStream(reviewJsonArray) + .map(JSONObject.class::cast) + .forEach(reviewJsonObject->{ + addRelevantUsersToList(reviewJsonObject); + }); - addRelevantUsersToList(reviewJsonObject); - } - } +// for (Object object : reviewJsonArray) { +// if (object instanceof JSONObject) { +// JSONObject reviewJsonObject = (JSONObject) object; +// +// +// } +// } } else { System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); + logger.info("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 2145a3a..6b4469b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -68,15 +68,18 @@ public Map> getFilesChanged(String repositoryName, Str IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); + ArrayList tempFileNames=new ArrayList<>(); + ArrayList 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 -> { - fileNames.add(commitFile.getFilename()); - patchString.add(commitFile.getPatch()); + tempFileNames.add(commitFile.getFilename()); + tempPatchString.add(commitFile.getPatch()); }); logger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); - mapWithFileNamesAndPatches.put("fileNames", fileNames); - mapWithFileNamesAndPatches.put("patchString", patchString); + mapWithFileNamesAndPatches.put("fileNames", tempFileNames); + mapWithFileNamesAndPatches.put("patchString", tempPatchString); logger.info("map with the modified file names with their relevant modified line ranges are saved successfully"); } catch (IOException e) { throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ", e);