Skip to content
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

Open
wants to merge 55 commits into
base: master
Choose a base branch
from

Conversation

kasunsiyambalapitiya
Copy link
Contributor

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.

kasunsiyambalapitiya and others added 30 commits March 10, 2017 09:33
Add log messages for all classes
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
@kasunsiyambalapitiya kasunsiyambalapitiya changed the title few changes from code review 2 fixes from code review part 1 Mar 31, 2017

}


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

Copy link
Contributor Author

@kasunsiyambalapitiya kasunsiyambalapitiya Mar 31, 2017

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();

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

Copy link
Contributor Author

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);

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.

Copy link
Contributor Author

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");

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.

Copy link
Contributor Author

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;
Copy link

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.

Copy link
Contributor Author

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 " _"

Copy link
Contributor Author

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/" +
Copy link

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.

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.

Copy link
Contributor Author

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"));

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks fixed it

<artifactId>wso2</artifactId>
<version>5</version>
</parent>
<groupId>org.wso2.codeQualityMatrices</groupId>
Copy link

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed it

<artifactId>wso2</artifactId>
<version>5</version>
</parent>
<groupId>org.wso2.codeQualityMatrices</groupId>
<artifactId>CodeQualityMatrices</artifactId>
Copy link

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?

Copy link
Contributor Author

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 {
Copy link

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;
Copy link

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 {
Copy link

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
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no since tag

Copy link
Contributor Author

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
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no since tag

Copy link
Contributor Author

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
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no since tag

Copy link
Contributor Author

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
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no since tag

Copy link
Contributor Author

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
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no since tag

Copy link
Contributor Author

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"));

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.

Copy link
Contributor Author

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) {
Copy link

@NipunaMarcus NipunaMarcus Mar 31, 2017

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed it 25560d7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants