-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify to identify only the changed lines from a given patch #2
base: master
Are you sure you want to change the base?
Conversation
Add log messages for all classes
in the pull request kasunsiyambalapitiya/CodeQualityMatricesProject#1 format the code
added streams for saveReviewersToList method added streams for savePrNumberAndRepoName method replaced for loop with for each loop in readTheReviewOutJSON method
add constants for Reviewers.java
Handle the response code recieved from Graphql API Correct the message thrown in Exception
try { | ||
String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); | ||
if (jsonText != null) { | ||
// Type listType = new TypeToken<List<ReviewApiResponse>>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
public class Author { | ||
|
||
@SerializedName("date") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
private String commitHash; | ||
|
||
@SerializedName("commit") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
@Test | ||
public void testSaveRepoNames() throws CodeQualityMetricsException { | ||
Map<String, List<String>> commitHashWithRepoNames = new HashMap<>(); | ||
commitHashWithRepoNames.put("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These hashes seems to be used in multiple places. So might be able to use a constant.
/** | ||
* This is a utility class for calling APIs. | ||
* | ||
* @since 1.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc line is not used AFAIR. Better to check for consistency with other repositories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked with few WSO2 repos, some contain @SInCE tag some doesn't, since this is a class level doc comment I think it is better to have it, What is your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kasunsiyambalapitiya : I think what chamila meant was don't use "This" word in the doc section. We all know that the doc is related to "This". So we can just say "Utility class for calling APIs".
BufferedReader bufferedReader = null; | ||
CloseableHttpClient httpClient; | ||
CloseableHttpResponse httpResponse = null; | ||
httpClient = HttpClients.createDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to instantiate at the same line where this is declared?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
String jsonText; | ||
try { | ||
httpResponse = httpClient.execute(httpGet); | ||
int responseCode = httpResponse.getStatusLine().getStatusCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for httpResponse.getStatusLine()
to return null
? If so this might be a possible NPE producer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handled NPE in 698c71e
int responseCode = httpResponse.getStatusLine().getStatusCode(); | ||
if (responseCode == 200) { | ||
//success | ||
bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with httpResponse.getEntity()
. When chaining calls, better to verify for possible NPEs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
if (args.length == 3) { | ||
String pmtToken = args[0]; | ||
String patchId = args[1]; | ||
String gitHubToken = args[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, it might be better to offload tokens to a config file and only accept the patch ID as an argument, as tokens tend to be reused again and would be cumbersome to enter in the command line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
* | ||
* @since 1.0.0 | ||
*/ | ||
public class GithubApiCaller { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a util class and could be final and methods could be static as there doesn't seem to be any state to be preserved between calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted to a Util class in 698c71e
* @since 1.0.0 | ||
*/ | ||
public class PmtApiCaller { | ||
public PmtApiCaller() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this constructor declared? Leftover from any refactoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) Removed in 698c71e
* @return a map of pull requests againt their repository name | ||
* @throws CodeQualityMetricsException results | ||
*/ | ||
Map<String, Set<Integer>> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be default access? Can it be private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method is called from a test case private access cannot be given
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kasunsiyambalapitiya : You can give private access even it is used in a test case. AFAIK, you can use java reflection to temporary change the access modifier before calling this method from the test case.
* under the License. | ||
*/ | ||
|
||
package com.wso2.code.quality.metrics.model; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this class contains all the constants used in the project, then it might belong at the parent level of the package hierarchy, or under a separate util
package.
private String graphqlInputWithoutHistory; | ||
private static final long serialVersionUID = 42L; | ||
|
||
public Graphql() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary declaration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it maven build fails giving this error com.wso2.code.quality.metrics.model.Graphql is Serializable; consider declaring a serialVersionUID [com.wso2.code.quality.metrics.model.Graphql] At Graphql.java:[lines 32-44] SE_NO_SERIALVERSIONID
. I fixed it as mentioned in the answer by "Jon Skeet" in http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it or else we need to avoid implementing Serializable
interface. What is the best way to handle it?
public class GraphqlCommit { | ||
@SerializedName("author") | ||
private GraphqlAuthor author; | ||
@SerializedName("history") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to keep a new line between properties to improve readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
log4j.appender.CONSOLE= org.apache.log4j.ConsoleAppender | ||
log4j.appender.CONSOLE.Target=System.out | ||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary new lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
* @since 1.0.0 | ||
*/ | ||
public class Token { | ||
final String pmtToken = "tQU5vxzrGeBpLMQuwOsJW_fyYLYa"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be extracted out to the properties file? Looks like a hard coded config value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to run any code coverage runs for the project? Do the unit tests cover important logic?
int responseCode = httpResponse.getStatusLine().getStatusCode(); | ||
if (responseCode == 200) { | ||
//success | ||
bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use try with resource style for readers. Then you don't need to close them explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
* @throws CodeQualityMetricsException results | ||
*/ | ||
public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMetricsException { | ||
BufferedReader bufferedReader = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible use java7 try with resource style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
} | ||
return ApiUtility.callGraphQlApi(httpPost); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add call to al the methods? can we think of something like search, getHistory etc..
try { | ||
Properties defaultProperties = new Properties(); | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
InputStream inputStream = classLoader.getResourceAsStream("url.properties"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to close the InputStreams
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
IssueApiResponse issueApiResponse = gson.fromJson(jsonText, IssueApiResponse.class); | ||
issueApiResponse.getIssue().parallelStream() | ||
.filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getStateOfThePr())) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove blank line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
result = IOUtils.toString(classLoader.getResourceAsStream(path)); | ||
} catch (IOException e) { | ||
logger.debug(e.getMessage(), e.getCause()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why exception is ignored here. better throw the exception. if we need to ignore, log it as an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
*/ | ||
public class SearchItem { | ||
@SerializedName("state") | ||
private String stateOfThePr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better if we can change the variable name to prState
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 698c71e
close resources with try with resources Seperate tokens to a property file Fix bug from history simplificatio If two commits in the history of a file cancel each other out (the changes are reversed), then Git detect this and simplifies the git log output of the file by leaving out those two commits.
README.md
Outdated
## Installation | ||
### Prerequisites | ||
* [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed. | ||
* [Java](http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html) installed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing . at the end.
@kasunsiyambalapitiya : Please remove the |
ad276dd
to
4ceb48f
Compare
8622a82
to
2c3e00e
Compare
Previous program considered a line range containing the modified lines from the given patch, for finding the authors, author commits and approved reviewers. As asked in the second code review the code is changed to detect exact lines been modified from the given patch and find authors, author commits and approved reviewers of those lines. This PR also contains all the modifications asked in PR1 https://github.com/wso2-incubator/code-quality-matrices/pull/1
Note:
At present the program works well for all WSO2 patches except the patches containing octopus merge commits ( commits having more than 2 parents) which may rarely available in WSO2 repositories