-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 List fine-grained personal access tokens with access to organization resources API #3215
Merged
gmlewis
merged 4 commits into
google:master
from
arymoraes:add-list-personal-access-tokens-api
Jul 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
04f9a42
feat: Add ListFineGrainedPersonalAccessTokens API
arymoraes 2a70832
feat: added ListFineGrainedPATOptions for ListFineGrainedPersonalAcce…
arymoraes e4b84aa
feat: Added multiple owners as query params on ListFineGranedPersonal…
arymoraes af4b0ab
feat: better comments explaining the owner parameter in ListFineGrain…
arymoraes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint can take a whole bunch more options:
So let's please create a new
type ListFineGrainedPATOptions struct { ... ListOptions }
that can take all these parameter, and make sure to addomitempty
to each one of them since they are optional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point and sorry for missing that. I added that on my latest commit.
One thing though, using the
owner
array aswill cause the API to return 422 status code, as it expects the
[]owner=...
format, so I had to create the helper function below.I tried to find an example on the codebase and I found
IssueListOptions
, but this one seems to work as that endpoint expects theorgs/{ORG}/issues?labels=bug%2Cfeature
formatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arymoraes - I'm looking all over the GitHub v3 API documentation and can't find
[]owner=...
anywhere.Where did you find this? It seems incredibly strange syntax to me for a query parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also found it very strange. I did not find it on the docs, but by trial and error (and by remembering seeing this kind of issue once).
If you run a CURL with:
It will give you a
422 status code error
:However:
Is valid and will indeed return you a list of tokens filtered by that owner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, wow, that is bizarre... so I was hoping that your unit test would show how multiple owners would appear in the resulting URL, but it doesn't... do they show up as comma-separated values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, it gets even weirder if you want multiple owners.
doesn't work, it'll just return an empty array of tokens (maybe if thinks the owner name is
owner1,owner2
?You have to do
To be able to filter tokens from any of those two owners. This is the one that is generated with
addListFineGrainedPATOptions
.I am finding this really weird, but this is the way it works even with curl, so I'm assuming this is indeed the way that GitHub API wants us to send the query param. I tried to search for others with the same question, but could not. I could take another look though.
I should probably improve the comment for
addListFineGrainedPATOptions
to add the multiple owners scenario, and maybe also test the URL explicitly on the unit test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's amazing... thank you for the details, @arymoraes !
Maybe could you please just add a comment explaining all this weirdness would be extremely helpful for anyone else that comes across this and tries to use it. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
I added the comments to the
addListFineGrainedPATOptions
helper function declaration, as well as insideaddListFineGrainedPATOptions
when we calladdListFineGrainedPATOptions
, so whoever runs into that code knows why we are doing this.