-
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
fixes from code review part 1 #1
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
|
||
} | ||
|
||
|
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.
Please remove unnecessary new 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.
Thanks,
fixed in 2ce10d0
} | ||
// creating a JSON object from the response | ||
jsonText = stringBuilder.toString(); | ||
|
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.
Please remove unnecessary new 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.
Thanks,
fixed in 2ce10d0
} | ||
} | ||
} | ||
logger.debug("The commit hashes are: " + commitHashes); |
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.
It is better to use isDebug option here and log the debug message.
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.
Thanks,
fixed in 2ce10d0
String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; | ||
try { | ||
httpGet = new HttpGet(url); | ||
httpGet.addHeader("Accept", "application/vnd.github.mercy-preview+json"); |
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 we create constants for these Strings ? "Accept" and "Authorization" are used in multiple places.
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.
Thanks,
fixed in 2ce10d0
* Pojo class used for parsing JSON response received from github REST API | ||
*/ | ||
public class Repository { | ||
private String full_name; |
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 use camel notation when naming variables.
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.
camel case notation cannot be used in here as we need to use the same field name in the JSON for mapping with GSON. For example in https://api.github.com/repos/wso2/wso2-axis2-transports/commits/e3c3457149b109178d510aac965d5a85cc465aa0 "html_url", "comments_url" fields are named with having " _"
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.
fix it as discussed by using "@SerializedName" annotation in each pojo class
* @throws CodeQualityMatricesException | ||
*/ | ||
public String callApi(String accessToken, String patchId) throws CodeQualityMatricesException { | ||
String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/" + |
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.
Might be better to read this URL via a configuration parameter, otherwise if the PMT URL change at some point, this code would need to be re-compiled.
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.
+1 . We should get these type of values through a separate configuration.
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.
Thanks, fixed it in 25560d7
if (responseCode == 200) { | ||
//success | ||
bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), | ||
"UTF-8")); |
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 think we can use StandardCharsets.UTF_8 for "UTF-8"
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.
Thanks fixed it
org.wso2.codequalitymatrices/pom.xml
Outdated
<artifactId>wso2</artifactId> | ||
<version>5</version> | ||
</parent> | ||
<groupId>org.wso2.codeQualityMatrices</groupId> |
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 think the practice is to use lower case, not uppercase
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.
Thanks, fixed it
org.wso2.codequalitymatrices/pom.xml
Outdated
<artifactId>wso2</artifactId> | ||
<version>5</version> | ||
</parent> | ||
<groupId>org.wso2.codeQualityMatrices</groupId> | ||
<artifactId>CodeQualityMatrices</artifactId> |
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 think the practice is to use lower case, not uppercase and shall we use hyphen(-) to separate out different words, for ex: code-quality-matrices?
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.
Thanks, fixed it
* @return String representation of the json response | ||
* @throws CodeQualityMatricesException | ||
*/ | ||
public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatricesException { |
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.
we can move this method to GithubApiCaller.
* @since 1.0.0 | ||
*/ | ||
public class GithubApiCaller { | ||
private HttpGet httpGet; |
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.
You can make this instance variable a local one and make this class a static one, WDYT?
* | ||
* @since 1.0.0 | ||
*/ | ||
public class 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.
As same as GithubApiCaller, we can make PmtApiCaller, a static one too, reason -> as we do not see any use of instance variables, WDYT?
|
||
/** | ||
* Pojo class used for parsing JSON response received from github REST API | ||
*/ |
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.
no since tag
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.
Thanks, fixed it
|
||
/** | ||
* Pojo class used for parsing JSON response received from github REST API | ||
*/ |
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.
no since tag
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.
Thanks, fixed it
|
||
/** | ||
* Pojo class used for parsing JSON response received from github REST API | ||
*/ |
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.
no since tag
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.
Thanks, fixed it
|
||
/** | ||
* Pojo class used for parsing JSON response received from github REST API | ||
*/ |
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.
no since tag
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.
Thanks, fixed it
|
||
/** | ||
* Pojo class used for parsing JSON response received from github REST API | ||
*/ |
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.
no since tag
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.
Thanks, fixed it
int responseCode = httpResponse.getStatusLine().getStatusCode(); | ||
if (responseCode == 200) { | ||
bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), | ||
"UTF-8")); |
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.
Here also please use the given constants as nisala mentioned above instead of using string.
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.
Thanks, fixed it
throw new CodeQualityMatricesException("Error occurred while calling PMT API", e); | ||
} | ||
Gson gson = new Gson(); | ||
if (jsonText != 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.
can we move gson initialization into if(jsonText != null){} block? so if the condition failed no need to create such a instance as it is used only inside that IF block. (Its a "nice to have" one. But that won't be much of a different to the performance though.)
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.
Thanks, fixed it 25560d7
6d4c965
to
25560d7
Compare
8622a82
to
2c3e00e
Compare
Added the changes asked in the code review 2,
Separate Github communication and PMT communication to separate classes.
Use a utility class for accessing APIs of both PMT and Github.
Use Gson for manipulating JSON responses.
Avoid using the exact field names in the API responses as variable names ( Ex patchInformation_svnRevisionpublic in PMT API).
Log the the exceptions occurred in closing resources than throwing them.
Avoid use of multiple exit codes and avoid exiting in multiple places in the program instead throw an exception and use a definite place to exit the program.
Convert all logger.info to logger.debug messages.
Use meaningful variable names inside the lamda expression.
Use lists in all possible times instead of using arrays.
Use forEach() directly for Lists instead of using stream().forEach()
Swap if statements to the maximum possible.
Use a bean class to create the JSON structure required for calling github graphql API.
except using Feing for calling APIs and adding test cases. They will be available in the next pull request.