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

Applied Refactoring #1638

Closed
wants to merge 4 commits into from
Closed

Applied Refactoring #1638

wants to merge 4 commits into from

Conversation

BadhriNadh
Copy link

@BadhriNadh BadhriNadh commented Apr 6, 2023

Description

  1. Variable 'v' does not have any meaning. So, renamed as 'includeReadNotifications', 'restrictedToParticipatingNotifications' and ‘pollIntervalHeaderValue’.
  2. Extracted a block to new method named 'getLatestUnReturnedThread',
  3. Extracted a block to new method named 'waitUntilNextPollingTime'
  4. Extracted a block to new method named 'updateThreadsAndMetadataFromGitHub'
  5. Moved condition to a function that returns a boolean.
  6. The ‘hashcode’ method in this class hierarchy [GHUser -> GHRepository] is overridden in a subclass and is only utilized in that subclass without being used in any other classes in the hierarchy. Therefore, the implementation of the hashcode method has been moved down to the subclass where it is actually used to simplify the parent class and make the code more modular.
  7. The ‘getApiRoute’ method was present in multiple subclasses, but with slight implementation differences. To address this, I used the Template Method pattern and pulled-up the method to the parent class. This eliminated code duplication, simplified the codebase, and made it easier to maintain and update the common code. <--This is fixing a potential issue-->
  8. Method ‘getApiTail’ has almost the same implementation in four classes: GHBlobBuilder, GHCommitBuilder, GHCommitComment, and GHTreeBuilder. It's also causing feature envy smell with GHRepository so moved these methods to GHRepository into one method. <--This is fixing a potential issue-->

Before submitting a PR:

  • Changes must not break binary backwards compatibility. If you are unclear on how to make the change you think is needed while maintaining backward compatibility, CONTRIBUTING.md for details.
  • Add JavaDocs and other comments as appropriate. Consider including links in comments to relevant documentation on https://docs.github.com/en/rest .
  • Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See CONTRIBUTING.md for details.
  • Run mvn -D enable-ci clean install site locally. If this command doesn't succeed, your change will not pass CI.
  • Push your changes to a branch other than main. You will create your PR from that branch.

When creating a PR:

  • Fill in the "Description" above with clear summary of the changes. This includes:
    • If this PR fixes one or more issues, include "Fixes #" lines for each issue.
    • Provide links to relevant documentation on https://docs.github.com/en/rest where possible.
  • All lines of new code should be covered by tests as reported by code coverage. Any lines that are not covered must have PR comments explaining why they cannot be covered. For example, "Reaching this particular exception is hard and is not a particular common scenario."
  • Enable "Allow edits from maintainers".

@bitwiseman bitwiseman self-requested a review April 14, 2023 16:42
@@ -190,4 +192,16 @@ public void append(StringBuffer buffer, String fieldName, Object value, Boolean
super.append(buffer, fieldName, value, fullDetail);
}
};

public String getApiRoute(GHRepository owner) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public String getApiRoute(GHRepository owner) {
protected final String getApiRoute(GHRepository owner) {

Copy link
Member

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

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

Generally approve of these refactors. Some questions/requests.

Comment on lines +3590 to +3600
public String getApiTail(String resourceType){
switch (resourceType) {
case "commits":
return String.format("/repos/%s/%s/git/commits", getOwnerName(), getName());
case "blobs":
return String.format("/repos/%s/%s/git/blobs", getOwnerName(), getName());
case "comments":
return String.format("/repos/%s/%s/comments/%s", getOwnerName(), getName(), getId());
case "trees":
return String.format("/repos/%s/%s/git/trees", getOwnerName(), getName());
}
Copy link
Member

Choose a reason for hiding this comment

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

The makes GHRepository have to know about paths for other resource types. I think this information should be in the classes for those resource types, not here. Extending this out will result in GHRepository have these string for most other resources.

But I'm open to more discussion if you feel strongly about this.

return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/");
}
@Override
protected String getApiRouteImpl() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't love this *Impl pattern, but it makes sense here.

@BadhriNadh
Copy link
Author

Need a different approach for this api

@BadhriNadh BadhriNadh closed this Apr 21, 2023
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.

None yet

2 participants