Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

feat: Add ListFineGrainedPersonalAccessTokenRequests for org#4022

Open
AbhishekAg wants to merge 4 commits intogoogle:masterfrom
AbhishekAg:abhi/fine_grained_PAT_requests
Open

feat: Add ListFineGrainedPersonalAccessTokenRequests for org#4022
AbhishekAg wants to merge 4 commits intogoogle:masterfrom
AbhishekAg:abhi/fine_grained_PAT_requests

Conversation

@AbhishekAg
Copy link
Contributor

@AbhishekAg AbhishekAg commented Feb 18, 2026

Implement support for listing requests to access organization resources via fine-grained personal access tokens (GET /orgs/{org}/personal-access-token-requests).

  • Add FineGrainedPersonalAccessTokenRequests struct for request details
    (id, reason, owner, repository selection, permissions, timestamps, token info)
  • Add ListFineGrainedPATRequestOptions with TokenID filter and embedded
    ListFineGrainedPATOptions (sort, direction, owner, repository, permission, last_used_before/after, pagination)
  • Add OrganizationsService.ListFineGrainedPersonalAccessTokenRequests
  • Add addListFineGrainedPATRequestOptions helper for owner[] and token_id[] query parameters

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

@gmlewis gmlewis changed the title Add ListFineGrainedPersonalAccessTokenRequests for org PAT request listing feat: Add ListFineGrainedPersonalAccessTokenRequests for org PAT request listing Feb 18, 2026
@gmlewis gmlewis changed the title feat: Add ListFineGrainedPersonalAccessTokenRequests for org PAT request listing feat: Add ListFineGrainedPersonalAccessTokenRequests for org Feb 18, 2026
@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Feb 18, 2026
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.07%. Comparing base (a2d86b0) to head (d109c37).

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

@AbhishekAg
Copy link
Contributor Author

@gmlewis Can you please re-run the pipeline? linter error is due to 503

validating openapi_operations.yaml
unexpected status code: 503 Service Unavailable
failed validating openapi_operations.yaml
validating generated files

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

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]>
@AbhishekAg
Copy link
Contributor Author

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

Done.

@AbhishekAg AbhishekAg requested a review from gmlewis February 20, 2026 04:19
Copy link
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

The response schema for this endpoint has all of the struct fields as required so is there a reason we're using pointers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@AbhishekAg
Copy link
Contributor Author

Pipeline failure due to

--- FAIL: TestRepositoriesService_RemoveCollaborator_invalidUser (0.00s)
    testing.go:1712: race detected during execution of test
--- FAIL: TestRepositoriesService_UploadReleaseAssetFromRelease_AbsoluteTemplate (0.04s)
    testing.go:1712: race detected during execution of test

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 20, 2026

Pipeline failure due to

--- FAIL: TestRepositoriesService_RemoveCollaborator_invalidUser (0.00s)
    testing.go:1712: race detected during execution of test
--- FAIL: TestRepositoriesService_UploadReleaseAssetFromRelease_AbsoluteTemplate (0.04s)
    testing.go:1712: race detected during execution of test

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove this empty line:

Suggested change

}

// FineGrainedPersonalAccessTokenRequest represents the details of a request to access organization resources via a fine-grained personal access token.
type FineGrainedPersonalAccessTokenRequest struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

options name = method name + "Options" suffix

s is missing:

Suggested change
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) {

Comment on lines +162 to +165
// TokenID filters results by the given fine-grained personal access token IDs.
TokenID []int64 `url:"-"`

ListFineGrainedPATOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@alexandear alexandear left a comment

Choose a reason for hiding this comment

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

By the way, did you check ListFineGrainedPersonalAccessTokenRequests by calling it on a real organization instead of using mocked data?

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 20, 2026

If GitHub doesn’t send some fields, that’s a mistake on GitHub’s side.

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).
Granted that GitHub was not even providing response schemas in the early days.

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?

@alexandear
Copy link
Contributor

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?

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

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 20, 2026

OK, @AbhishekAg, let's run with the recommendations from @stevehipwell and @alexandear.
I apologize for steering you in the wrong direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API Endpoint for listing fine grained personal access token requests

4 participants