Skip to content

Conversation

@gounthar
Copy link

@gounthar gounthar commented Dec 10, 2024

First attempt at fixing issue #1993.

I'm aware that the tests aren't passing. 🤷 Implementing them involved a series of unsuccessful guesses. That's also why I attempted to add some configuration for the mocking part, but unfortunately, it didn't work out.

[ERROR] Errors:
[ERROR]   GHRepositoryTest.testCreateForkWithInvalidParameters »  Unexpected exception, expected<java.lang.IllegalArgumentException> but was<org.kohsuke.github.GHFileNotFoundException>
[ERROR]   GHRepositoryTest.testCreateForkWithValidParameters:834->getRepository:50->getRepository:54 » GHFileNotFound http://localhost:38075/orgs/hub4j-test-org No response could be served as there are no stub mappings in this WireMock instance.
[INFO]
[ERROR] Tests run: 518, Failures: 0, Errors: 2, Skipped: 21
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

I hope my use of @Deprecated(forRemoval = true) wasn't too extreme. 🤞

Description

  • New Features

    • Introduced a new method for creating forks with enhanced flexibility, including options for organization and repository name.
  • Bug Fixes

    • "Improved" error handling for invalid parameters in the new forking method.
  • Tests

    • Added half-baked tests for the new forking method, badly covering both valid and invalid parameter scenarios.
  • Chores

    • "Enhanced" mocking capabilities for testing the new forking functionality.

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.

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. If not including links, explain why not.
  • 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".

* Signals that an I/O exception has occurred.
*/
@Test
public void testCreateForkWithValidParameters() throws IOException {
Copy link
Member

@bitwiseman bitwiseman Dec 12, 2024

Choose a reason for hiding this comment

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

Take a look at the test for forkTo():

@Test
public void testOrgFork() throws Exception {
cleanupRepository(GITHUB_API_TEST_ORG + "/rubywm");
gitHub.getRepository("kohsuke/rubywm").forkTo(gitHub.getOrganization(GITHUB_API_TEST_ORG));
}

That might help.

Note, it uses GITHUB_API_TEST_ORG but you can you a different org while you're trying things out. When you're basically ready, we can re-record the using GITHUB_API_TEST_ORG .

@bitwiseman
Copy link
Member

Solid start on this. Made some suggestions. Happy to discuss further. Please ask if you have questions.

Comment on lines +1501 to +1515
/**
* Creates a fork of this repository with optional parameters.
*
* @param organization
* the organization to fork to, or null to fork to the authenticated user's account
* @param name
* the name of the new repository, or null to use the same name as the original repository
* @param defaultBranchOnly
* whether to fork only the default branch
* @return the newly forked repository
* @throws IOException
* if an I/O error occurs
*/
public GHRepository createFork(@Nullable String organization, @Nullable String name, boolean defaultBranchOnly)
throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

You did basically exactly what I ask for with the deprecations, thanks!
Did you leave out the public GHRepository createFork() intentionally or just WIP?
If you still plan to provide the method overload with few parameters, the right signature is public GHRepository createFork(boolean defaultBranchOnly) instead of no parameters. What are your thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

WiP, definitely. I'll work on it, thanks!

@gounthar
Copy link
Author

I can't find the time to finish it properly, sorry.

@gounthar gounthar closed this Jan 21, 2025
@jonesbusy
Copy link
Contributor

#1995 has been merged

@bitwiseman
Copy link
Member

@gounthar
Thanks for taking a swing at it. Next time!

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