feat: Add ListFineGrainedPersonalAccessTokenRequests for org#4022
feat: Add ListFineGrainedPersonalAccessTokenRequests for org#4022AbhishekAg wants to merge 4 commits intogoogle:masterfrom
ListFineGrainedPersonalAccessTokenRequests for org#4022Conversation
…sting Signed-off-by: abhishek <[email protected]>
ListFineGrainedPersonalAccessTokenRequests for org PAT request listing
ListFineGrainedPersonalAccessTokenRequests for org PAT request listingListFineGrainedPersonalAccessTokenRequests for org
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4022 +/- ##
==========================================
+ Coverage 94.04% 94.07% +0.02%
==========================================
Files 207 207
Lines 19206 19262 +56
==========================================
+ Hits 18063 18121 +58
+ Misses 940 939 -1
+ Partials 203 202 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: abhishek <[email protected]>
|
@gmlewis Can you please re-run the pipeline? linter error is due to 503 |
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @AbhishekAg!
Once you add omitempty to the pointer fields in FineGrainedPersonalAccessTokenRequests then I think we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.
cc: @stevehipwell - @alexandear - @zyfy29 - @Not-Dhananjay-Mishra
Signed-off-by: abhishek <[email protected]>
Done. |
Signed-off-by: abhishek <[email protected]>
stevehipwell
left a comment
There was a problem hiding this comment.
I may be missing something but to me the struct pattern doesn't look right/consistent?
| } | ||
|
|
||
| // FineGrainedPersonalAccessTokenRequest represents the details of a request to access organization resources via a fine-grained personal access token. | ||
| type FineGrainedPersonalAccessTokenRequest struct { |
There was a problem hiding this comment.
The response schema for this endpoint has all of the struct fields as required so is there a reason we're using pointers?
There was a problem hiding this comment.
@stevehipwell - @alexandear pointed this out above, and I reminded everyone about our README.md which says that for responses representing GitHub resources, we use pointers and omitempty so that as users we can tell when GitHub does not send a field. Because historically, GitHub will sometimes send fields and sometimes not send fields in a response.
So @AbhishekAg originally had values without omitempty and I asked him to change them to pointers and omitempty because this is a returned response from GitHub representing a GitHub resource. This is how we treat the rest of the repo and I feel we should be consistent.
Thoughts?
There was a problem hiding this comment.
I think all fields are not mandatory. Example: reason may be null when no reason is provided while requesting for fine grained PAT.
That's why we have added omitempty in every field
There was a problem hiding this comment.
According to the response schema, all fields are mandatory:
"required": [
"id",
"reason",
"owner",
"repository_selection",
"repositories_url",
"permissions",
"created_at",
"token_id",
"token_name",
"token_expired",
"token_expires_at",
"token_last_used_at"
]
}
}As I recall, we try to strictly follow the schema, and sometimes, if there are reported bugs, we can work around them using omitempty. If GitHub doesn’t send some fields, that’s a mistake on GitHub’s side.
I agree with @stevehipwell and suggest removing omitempty and pointers from all fields.
|
Pipeline failure due to |
Unfortunately, we appear to be having some flaky tests, which @alexandear also noticed and filed an issue: #3987. I'm not sure at what point this started getting flaky, but it feels like it is pretty recent. I reran the failed job. |
| } | ||
|
|
||
| var pats []*FineGrainedPersonalAccessTokenRequest | ||
|
|
There was a problem hiding this comment.
Let's remove this empty line:
| } | ||
|
|
||
| // FineGrainedPersonalAccessTokenRequest represents the details of a request to access organization resources via a fine-grained personal access token. | ||
| type FineGrainedPersonalAccessTokenRequest struct { |
There was a problem hiding this comment.
According to the response schema, all fields are mandatory:
"required": [
"id",
"reason",
"owner",
"repository_selection",
"repositories_url",
"permissions",
"created_at",
"token_id",
"token_name",
"token_expired",
"token_expires_at",
"token_last_used_at"
]
}
}As I recall, we try to strictly follow the schema, and sometimes, if there are reported bugs, we can work around them using omitempty. If GitHub doesn’t send some fields, that’s a mistake on GitHub’s side.
I agree with @stevehipwell and suggest removing omitempty and pointers from all fields.
| // GitHub API docs: https://docs.github.com/rest/orgs/personal-access-tokens#list-requests-to-access-organization-resources-with-fine-grained-personal-access-tokens | ||
| // | ||
| //meta:operation GET /orgs/{org}/personal-access-token-requests | ||
| func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequests(ctx context.Context, org string, opts *ListFineGrainedPATRequestOptions) ([]*FineGrainedPersonalAccessTokenRequest, *Response, error) { |
There was a problem hiding this comment.
options name = method name + "Options" suffix
s is missing:
| func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequests(ctx context.Context, org string, opts *ListFineGrainedPATRequestOptions) ([]*FineGrainedPersonalAccessTokenRequest, *Response, error) { | |
| func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequests(ctx context.Context, org string, opts *ListFineGrainedPATRequestsOptions) ([]*FineGrainedPersonalAccessTokenRequest, *Response, error) { |
| // TokenID filters results by the given fine-grained personal access token IDs. | ||
| TokenID []int64 `url:"-"` | ||
|
|
||
| ListFineGrainedPATOptions |
There was a problem hiding this comment.
ListFineGrainedPATOptions also contains TokenID: according to the doc
https://docs.github.com/en/rest/orgs/personal-access-tokens?apiVersion=2022-11-28#list-fine-grained-personal-access-tokens-with-access-to-organization-resources
So, let's add TokenID to the ListFineGrainedPATOptions, update addListFineGrainedPATOptions, and use ListFineGrainedPATOptions here instead of ListFineGrainedPATRequestOptions.
alexandear
left a comment
There was a problem hiding this comment.
By the way, did you check ListFineGrainedPersonalAccessTokenRequests by calling it on a real organization instead of using mocked data?
Yes, and over the last 10+ years, we've seen that a fair amount... mostly in the early days (hence the stance in our README.md). OK, so your argument is that now that GitHub IS providing response schemas, and we are building a new endpoint based upon that schema, that we should initially attempt to honor it and fix bugs as they occur. I totally understand that argument. As a maintainer, we wish that everything could be 100% consistent and cut-and-dry and make perfect sense. So my next thought is... now that GitHub response schemas are prolific, do we now go back and clean up every struct this repo generates for GitHub resources and make the fields match the schemas?!? Are we opening up an enormous can of worms? Thoughts? |
We can do this in the future, but we need to make sure it won't break anything. So we should limit these changes to endpoints that have integration tests. Or maybe we need to add more integration tests, but it's hard for some endpoints (e.g., enterprise or org-related). |
|
OK, @AbhishekAg, let's run with the recommendations from @stevehipwell and @alexandear. |
Implement support for listing requests to access organization resources via fine-grained personal access tokens (GET /orgs/{org}/personal-access-token-requests).
(id, reason, owner, repository selection, permissions, timestamps, token info)
ListFineGrainedPATOptions (sort, direction, owner, repository, permission, last_used_before/after, pagination)
API docs: https://docs.github.com/en/rest/orgs/personal-access-tokens#list-requests-to-access-organization-resources-with-fine-grained-personal-access-tokens
Fixes: #4021