8000 FEAT: Implement enabling auto merge for PR by GraphQL by seate · Pull Request #2056 · hub4j/github-api · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

FEAT: Implement enabling auto merge for PR by GraphQL #2056

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

Merged
merged 10 commits into from
Mar 19, 2025
Merged

Conversation

seate
Copy link
Contributor
@seate seate commented Mar 10, 2025

Description


Implement to enable Auto merge for PR by GraphQL.

  • Implement general GraphQL request, response support for the feature.

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

@seate seate force-pushed the main branch 2 times, most recently from 0757692 to c7f0d59 Compare March 10, 2025 21:23
@seate
Copy link
Contributor Author
seate commented Mar 15, 2025

@bitwiseman
Can you tell me about why tests failed?
What can I do?

@bitwiseman
Copy link
Member
 Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.097 s <<< FAILURE! -- in org.kohsuke.github.AotIntegrationTest
 org.kohsuke.github.AotIntegrationTest.testIfAllRequiredClassesAreRegisteredForAot -- Time elapsed: 0.096 s <<< FAILURE!
java.lang.AssertionError: 
The class "org.kohsuke.github.GHPullRequest$EnablePullRequestAutoMergeResponse" needs to be configured or excluded for reflection / serialization and was not mentioned in one of the following resources:

src/main/resources/META-INF/reflect-config.json - example:

  {
    "name": "org.kohsuke.github.GHPullRequest$EnablePullRequestAutoMergeResponse",
    "allPublicFields": true,
    "allDeclaredFields": true,
    "queryAllPublicConstructors": true,
    "queryAllDeclaredConstructors": true,
    "allPublicConstructors": true,
    "allDeclaredConstructors": true,
    "queryAllPublicMethods": true,
    "queryAllDeclaredMethods": true,
    "allPublicMethods": true,
    "allDeclaredMethods": true,
    "allPublicClasses": true,
    "allDeclaredClasses": true
  }

src/main/resources/META-INF/serialization.json - example:

  {
    "name": "org.kohsuke.github.GHPullRequest$EnablePullRequestAutoMergeResponse"
  }

src/test/resources/no-reflect-and-serialization-list - example:

  org.kohsuke.github.GHPullRequest$EnablePullRequestAutoMergeResponse

Please add it to either no-reflect-and-serialization-list or to serialization.json and / or reflect-config.json

@seate seate force-pushed the main branch 4 times, most recently from c5cb88b to b99a876 Compare March 17, 2025 08:40
Copy link
codecov bot commented Mar 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.83%. Comparing base (04af6e3) to head (cc0d0fd).
Report is 13 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2056      +/-   ##
============================================
+ Coverage     83.58%   83.83%   +0.24%     
- Complexity     2380     2412      +32     
============================================
  Files           235      236       +1     
  Lines          7262     7324      +62     
  Branches        382      389       +7     
============================================
+ Hits           6070     6140      +70     
+ Misses          956      952       -4     
+ Partials        236      232       -4     

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

String ownerName = owner.getOwnerName();

String graphqlBody = String.format(
"query GetPullRequestID { repository(name: \"%s\", owner: \"%s\") { pullRequest(number: %d) { id } } }",
Copy link
Member
@bitwiseman bitwiseman Mar 18, 2025

Choose a reason for hiding this comment

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

You might not need this method. I think this GraphQL id field is already available from GHPullRequest.getNodeId() (inherited from GHObject).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I didn't know it! I will change it.

@seate seate force-pushed the main branch 3 times, most recently from 1839bf6 to 0c63dfb Compare March 18, 2025 20:57
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.

Great! Some suggestions that will reduce the amount of code you'll need to cover with tests.

* if there is an I/O Exception.
*/
@CheckForNull
static <T> GHGraphQLResponse<T> parseGraphQLBody(GitHubConnectorResponse connectorResponse, Class<T> type)
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 think you need this specialized method either... using regular parseBody() should be enough, right?

Copy link
Contributor Author
@seate seate Mar 18, 2025

Choose a reason for hiding this comment

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

I thoght that using generic is better than just Object class in data field in GHGraphQLResponse class.
Because I thought this way is easier to get information by serialization than writing another method to get information.
And this can't be achieved by parseBody() when using generic field in GHGraphQLResponse class.

That's why I implemented this method.
Or there are some ways that this can be achieved that I don't know?

Copy link
Member
@bitwiseman bitwiseman Mar 19, 2025

Choose a reason for hiding this comment

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

Agreed generic is better.
And you're correct with a bare generic (such as GHGraphQLResponse<T>), you can pass the type - GHGraphQLResponse<GHSomeDataRecord>.class doesn't work.

But you can get around this limitation by creating a concrete class of the type you need.

public class GHSomeDataRecordResponse extends GHGraphQLResponse<GHSomeDataRecord> {
...
}

Then you can pass GHSomeDataRecordResponse.class.

In the case of sendGraphQL() the returned data is not read, so Object is fine and I created a GHGraphQLResponse.ObjectResponse.class for that.

6cf65e0#diff-02b0c52659b0fb57bd257b850d25db8da3763545e6e429dc24fc693510487ce0R114

@bitwiseman
Copy link
Member

@seate
Please consider not using force push for changes. It will make it easier to review changes. Thanks!

@seate
Copy link
Contributor Author
seate commented Mar 18, 2025

@seate Please consider not using force push for changes. It will make it easier to review changes. Thanks!

Oh I couldn't recognize your comment. sorry!
Thanks for your review. I will change it

@bitwiseman
Copy link
Member
bitwiseman commented Mar 19, 2025

@seate
Take a look at this. I'm saying this is the way to do this, but it is one way.

https://github.com/hub4j/github-api/tree/feat/pr-2056

Two commits in that branch:
6cf65e0

e093e6c

If you do a git pull from this repo, you can then git cherry-pick 6cf65e0ec && git cherry-pick e093e6c to apply this change to you PR.

@seate
Copy link
Contributor Author
seate commented Mar 19, 2025

@bitwiseman
Your suggestion is much better! I will apply it.

@bitwiseman bitwiseman self-requested a review March 19, 2025 15:26
@bitwiseman bitwiseman self-requested a review March 19, 2025 15:42
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.

Thanks for this PR! I know we made a bunch of changes, but I want to make you know that this was a good PR from the start. I especially appreciated the unit and functional tests. All the changes were tweaks to the solid base functionality.

I look forward to your future contributions.

@bitwiseman bitwiseman merged commit b759660 into hub4j:main Mar 19, 2025
12 checks passed
@seate
Copy link
Contributor Author
seate commented Mar 20, 2025

I apologize for my inexperience and appreciate to help my PR. It was great experience.
Next time, I hope that I can contribute in much better way.

@Haarolean
Copy link
Contributor

@seate thanks for implementing this!

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.

Allow a GHPullRequest to set auto-merge
4 participants
0