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

Add Support for Retrieving Template Repository Information for a Repo… #1817

Merged
merged 3 commits into from
Mar 18, 2024
Merged

Add Support for Retrieving Template Repository Information for a Repo… #1817

merged 3 commits into from
Mar 18, 2024

Conversation

jbenaventem
Copy link
Contributor

Description

Add Support for Retrieving Template Repository Information for a Repository #1812

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 explaining the behavior.
  • When adding or updating methods that fetch entities, add @link JavaDoc entries to the 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.

Copy link
Contributor

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I added some feeback and questions.

* @return the repository template
*/
public GHRepository getTemplateRepository() throws CloneNotSupportedException {
return (GHRepository) template_repository.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you clone() the repo? This looks odd to me (and I usually refrain from using clone()).

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I suspect you will have to inject the root in the repository, unless it's done automatically by Jackson.

In any case, adding a test to test that you can actually execute an operation on the repository after getting it would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The clone method was because I've found an spotbug error "EI_EXPOSE_REP: May expose internal representation by returning reference to mutable object", it's for that reason I implements Clonable in this object, and return an object copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to add the following annotation to the method instead:

@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, It's another posibility, but I unknow the project security rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I suspect you will have to inject the root in the repository, unless it's done automatically by Jackson.

In any case, adding a test to test that you can actually execute an operation on the repository after getting it would be better.

Sorry, my English is terrible, and I'm not sure about that comment.
Is the provided test sufficient?

    /**
     * Test get repository created from a template repository
     *
     * @throws Exception
     *             the exception
     */
    @Test
    public void testGetRepositoryWithTemplateRepositoryInfo() throws Exception {
        GHRepository testRepo = gitHub.getRepositoryById(repo.getId());
        assertThat(testRepo.getTemplateRepository(), notNullValue());
        assertThat(testRepo.getTemplateRepository().getOwnerName(), equalTo("octocat"));
        assertThat(testRepo.getTemplateRepository().isTemplate(), equalTo(true));
    }

src/main/java/org/kohsuke/github/GHRepository.java Outdated Show resolved Hide resolved
src/main/java/org/kohsuke/github/GHRepositoryBuilder.java Outdated Show resolved Hide resolved
src/main/java/org/kohsuke/github/GHRepository.java Outdated Show resolved Hide resolved
Copy link

codecov bot commented Mar 17, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 80.71%. Comparing base (1aa7178) to head (2105263).
Report is 4 commits behind head on main.

❗ Current head 2105263 differs from pull request most recent head 88cfdad. Consider uploading reports for the commit 88cfdad to get more accurate results

Files Patch % Lines
src/main/java/org/kohsuke/github/GHRepository.java 50.00% 2 Missing ⚠️
...n/java/org/kohsuke/github/GHRepositoryBuilder.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1817      +/-   ##
============================================
+ Coverage     80.66%   80.71%   +0.04%     
- Complexity     2342     2345       +3     
============================================
  Files           220      221       +1     
  Lines          7082     7119      +37     
  Branches        379      384       +5     
============================================
+ Hits           5713     5746      +33     
- Misses         1132     1136       +4     
  Partials        237      237              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jbenaventem
Copy link
Contributor Author

jbenaventem commented Mar 18, 2024

@gsmet Thank you for the review. I've resolved almost comments.
About this comment

Also I suspect you will have to inject the root in the repository, unless it's done automatically by Jackson.
In any case, adding a test to test that you can actually execute an operation on the repository after getting it would be better.

I'm not sure if with this solution provided is enought or you're waiting something more.....

/**
 * Test get repository created from a template repository
 *
 * @throws Exception
 *             the exception
 */
@Test
public void testGetRepositoryWithTemplateRepositoryInfo() throws Exception {
    GHRepository testRepo = gitHub.getRepositoryById(repo.getId());
    assertThat(testRepo.getTemplateRepository(), notNullValue());
    assertThat(testRepo.getTemplateRepository().getOwnerName(), equalTo("octocat"));
    assertThat(testRepo.getTemplateRepository().isTemplate(), equalTo(true));
}

@jbenaventem jbenaventem requested a review from gsmet March 18, 2024 12:12
@bitwiseman bitwiseman merged commit 5001541 into hub4j:main Mar 18, 2024
9 checks passed
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.

3 participants