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 repositories body parameter when creating installation access tokens #1492



Copy link


This PR adds support for the repositories body parameter as specified in to GHAppCreateTokenBuilder.

Originally, if you wanted to generate an installation access token limited to a specific repository, the /app/installations/{installation_id}/access_tokens endpoint required you to pass a repository_ids body parameter. That parameter is a bit awkward because generally you will need to make an additional API call to retrieve the ID of a repository given its name.

At some point (I could not find a changelog) GitHub added a repositories body parameter that works like repository_ids, but accepts repository names rather than IDs, which is a nice improvement.

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, for details.
  • Add JavaDocs and other comments as appropriate. Consider including links in comments to relevant documentation on .
  • Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See 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 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".

* Array containing the repository names
* @return a GHAppCreateTokenBuilder
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From a bit of reading I think this API is out of beta now, but I added this annotation anyways to match the other methods in this class. Let me know if I should remove the annotation or anything.

public void createTokenWithRepositories() throws IOException {
GHApp app = gitHub.getApp();
GHAppInstallation installation = app.getInstallationByUser("bogus");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IDK if this is the preferred approach, but it matches the above createToken test (I ran it against a real app and everything though when generating the stubs and then just changed the names to match the other test).

@bitwiseman bitwiseman self-requested a review August 8, 2022 16:58
Copy link

codecov bot commented Aug 8, 2022

Codecov Report

Merging #1492 (bd27d76) into main (08785e5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##               main    #1492   +/-   ##
  Coverage     78.80%   78.81%           
- Complexity     2113     2114    +1     
  Files           202      202           
  Lines          6427     6429    +2     
  Branches        361      361           
+ Hits           5065     5067    +2     
  Misses         1152     1152           
  Partials        210      210           
Impacted Files Coverage Δ 85.71% <100.00%> (+1.50%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bitwiseman bitwiseman merged commit 50ff967 into hub4j:main Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants