From 95029ec566517ad850f2e42a46976d11bab68e1c Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 18 Feb 2026 22:03:54 +0530 Subject: [PATCH 1/6] Add ListFineGrainedPersonalAccessTokenRequests for org PAT request listing Signed-off-by: abhishek --- github/github-accessors.go | 96 ++++++++++++ github/github-accessors_test.go | 126 +++++++++++++++ github/github-iterators.go | 31 ++++ github/github-iterators_test.go | 72 +++++++++ github/orgs_personal_access_tokens.go | 130 ++++++++++++++++ github/orgs_personal_access_tokens_test.go | 172 +++++++++++++++++++++ 6 files changed, 627 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index ec77299f2fe..b6e2951045d 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10478,6 +10478,102 @@ func (f *FieldValue) GetProjectNumber() int64 { return *f.ProjectNumber } +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetCreatedAt() Timestamp { + if f == nil || f.CreatedAt == nil { + return Timestamp{} + } + return *f.CreatedAt +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetID() int64 { + if f == nil || f.ID == nil { + return 0 + } + return *f.ID +} + +// GetOwner returns the Owner field. +func (f *FineGrainedPersonalAccessTokenRequests) GetOwner() *User { + if f == nil { + return nil + } + return f.Owner +} + +// GetPermissions returns the Permissions field. +func (f *FineGrainedPersonalAccessTokenRequests) GetPermissions() *PersonalAccessTokenPermissions { + if f == nil { + return nil + } + return f.Permissions +} + +// GetReason returns the Reason field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetReason() string { + if f == nil || f.Reason == nil { + return "" + } + return *f.Reason +} + +// GetRepositoriesURL returns the RepositoriesURL field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetRepositoriesURL() string { + if f == nil || f.RepositoriesURL == nil { + return "" + } + return *f.RepositoriesURL +} + +// GetRepositorySelection returns the RepositorySelection field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetRepositorySelection() string { + if f == nil || f.RepositorySelection == nil { + return "" + } + return *f.RepositorySelection +} + +// GetTokenExpired returns the TokenExpired field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetTokenExpired() bool { + if f == nil || f.TokenExpired == nil { + return false + } + return *f.TokenExpired +} + +// GetTokenExpiresAt returns the TokenExpiresAt field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetTokenExpiresAt() Timestamp { + if f == nil || f.TokenExpiresAt == nil { + return Timestamp{} + } + return *f.TokenExpiresAt +} + +// GetTokenID returns the TokenID field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetTokenID() int64 { + if f == nil || f.TokenID == nil { + return 0 + } + return *f.TokenID +} + +// GetTokenLastUsedAt returns the TokenLastUsedAt field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetTokenLastUsedAt() Timestamp { + if f == nil || f.TokenLastUsedAt == nil { + return Timestamp{} + } + return *f.TokenLastUsedAt +} + +// GetTokenName returns the TokenName field if it's non-nil, zero value otherwise. +func (f *FineGrainedPersonalAccessTokenRequests) GetTokenName() string { + if f == nil || f.TokenName == nil { + return "" + } + return *f.TokenName +} + // GetIdentifier returns the Identifier field if it's non-nil, zero value otherwise. func (f *FirstPatchedVersion) GetIdentifier() string { if f == nil || f.Identifier == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 08332e3776d..20134e5be03 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13614,6 +13614,132 @@ func TestFieldValue_GetProjectNumber(tt *testing.T) { f.GetProjectNumber() } +func TestFineGrainedPersonalAccessTokenRequests_GetCreatedAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + f := &FineGrainedPersonalAccessTokenRequests{CreatedAt: &zeroValue} + f.GetCreatedAt() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetCreatedAt() + f = nil + f.GetCreatedAt() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + f := &FineGrainedPersonalAccessTokenRequests{ID: &zeroValue} + f.GetID() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetID() + f = nil + f.GetID() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetOwner(tt *testing.T) { + tt.Parallel() + f := &FineGrainedPersonalAccessTokenRequests{} + f.GetOwner() + f = nil + f.GetOwner() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetPermissions(tt *testing.T) { + tt.Parallel() + f := &FineGrainedPersonalAccessTokenRequests{} + f.GetPermissions() + f = nil + f.GetPermissions() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetReason(tt *testing.T) { + tt.Parallel() + var zeroValue string + f := &FineGrainedPersonalAccessTokenRequests{Reason: &zeroValue} + f.GetReason() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetReason() + f = nil + f.GetReason() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetRepositoriesURL(tt *testing.T) { + tt.Parallel() + var zeroValue string + f := &FineGrainedPersonalAccessTokenRequests{RepositoriesURL: &zeroValue} + f.GetRepositoriesURL() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetRepositoriesURL() + f = nil + f.GetRepositoriesURL() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetRepositorySelection(tt *testing.T) { + tt.Parallel() + var zeroValue string + f := &FineGrainedPersonalAccessTokenRequests{RepositorySelection: &zeroValue} + f.GetRepositorySelection() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetRepositorySelection() + f = nil + f.GetRepositorySelection() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetTokenExpired(tt *testing.T) { + tt.Parallel() + var zeroValue bool + f := &FineGrainedPersonalAccessTokenRequests{TokenExpired: &zeroValue} + f.GetTokenExpired() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetTokenExpired() + f = nil + f.GetTokenExpired() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetTokenExpiresAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + f := &FineGrainedPersonalAccessTokenRequests{TokenExpiresAt: &zeroValue} + f.GetTokenExpiresAt() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetTokenExpiresAt() + f = nil + f.GetTokenExpiresAt() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetTokenID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + f := &FineGrainedPersonalAccessTokenRequests{TokenID: &zeroValue} + f.GetTokenID() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetTokenID() + f = nil + f.GetTokenID() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetTokenLastUsedAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + f := &FineGrainedPersonalAccessTokenRequests{TokenLastUsedAt: &zeroValue} + f.GetTokenLastUsedAt() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetTokenLastUsedAt() + f = nil + f.GetTokenLastUsedAt() +} + +func TestFineGrainedPersonalAccessTokenRequests_GetTokenName(tt *testing.T) { + tt.Parallel() + var zeroValue string + f := &FineGrainedPersonalAccessTokenRequests{TokenName: &zeroValue} + f.GetTokenName() + f = &FineGrainedPersonalAccessTokenRequests{} + f.GetTokenName() + f = nil + f.GetTokenName() +} + func TestFirstPatchedVersion_GetIdentifier(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-iterators.go b/github/github-iterators.go index cdff22217bb..ce2e9f8b424 100644 --- a/github/github-iterators.go +++ b/github/github-iterators.go @@ -4149,6 +4149,37 @@ func (s *OrganizationsService) ListFailedOrgInvitationsIter(ctx context.Context, } } +// ListFineGrainedPersonalAccessTokenRequestsIter returns an iterator that paginates through all results of ListFineGrainedPersonalAccessTokenRequests. +func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequestsIter(ctx context.Context, org string, opts *ListFineGrainedPATRequestOptions) iter.Seq2[*FineGrainedPersonalAccessTokenRequests, error] { + return func(yield func(*FineGrainedPersonalAccessTokenRequests, error) bool) { + // Create a copy of opts to avoid mutating the caller's struct + if opts == nil { + opts = &ListFineGrainedPATRequestOptions{} + } else { + opts = Ptr(*opts) + } + + for { + results, resp, err := s.ListFineGrainedPersonalAccessTokenRequests(ctx, org, opts) + if err != nil { + yield(nil, err) + return + } + + for _, item := range results { + if !yield(item, nil) { + return + } + } + + if resp.NextPage == 0 { + break + } + opts.ListOptions.Page = resp.NextPage + } + } +} + // ListFineGrainedPersonalAccessTokensIter returns an iterator that paginates through all results of ListFineGrainedPersonalAccessTokens. func (s *OrganizationsService) ListFineGrainedPersonalAccessTokensIter(ctx context.Context, org string, opts *ListFineGrainedPATOptions) iter.Seq2[*PersonalAccessToken, error] { return func(yield func(*PersonalAccessToken, error) bool) { diff --git a/github/github-iterators_test.go b/github/github-iterators_test.go index fc299ce307a..581a9030bed 100644 --- a/github/github-iterators_test.go +++ b/github/github-iterators_test.go @@ -9087,6 +9087,78 @@ func TestOrganizationsService_ListFailedOrgInvitationsIter(t *testing.T) { } } +func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequestsIter(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + var callNum int + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + callNum++ + switch callNum { + case 1: + w.Header().Set("Link", `; rel="next"`) + fmt.Fprint(w, `[{},{},{}]`) + case 2: + fmt.Fprint(w, `[{},{},{},{}]`) + case 3: + fmt.Fprint(w, `[{},{}]`) + case 4: + w.WriteHeader(http.StatusNotFound) + case 5: + fmt.Fprint(w, `[{},{}]`) + } + }) + + iter := client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter(t.Context(), "", nil) + var gotItems int + for _, err := range iter { + gotItems++ + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + } + if want := 7; gotItems != want { + t.Errorf("client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter call 1 got %v items; want %v", gotItems, want) + } + + opts := &ListFineGrainedPATRequestOptions{} + iter = client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter(t.Context(), "", opts) + gotItems = 0 + for _, err := range iter { + gotItems++ + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + } + if want := 2; gotItems != want { + t.Errorf("client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter call 2 got %v items; want %v", gotItems, want) + } + + iter = client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter(t.Context(), "", nil) + gotItems = 0 + for _, err := range iter { + gotItems++ + if err == nil { + t.Error("expected error; got nil") + } + } + if gotItems != 1 { + t.Errorf("client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter call 3 got %v items; want 1 (an error)", gotItems) + } + + iter = client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter(t.Context(), "", nil) + gotItems = 0 + iter(func(item *FineGrainedPersonalAccessTokenRequests, err error) bool { + gotItems++ + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + return false + }) + if gotItems != 1 { + t.Errorf("client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter call 4 got %v items; want 1 (an error)", gotItems) + } +} + func TestOrganizationsService_ListFineGrainedPersonalAccessTokensIter(t *testing.T) { t.Parallel() client, mux, _ := setup(t) diff --git a/github/orgs_personal_access_tokens.go b/github/orgs_personal_access_tokens.go index 8155ad402bf..9cf687e6b3e 100644 --- a/github/orgs_personal_access_tokens.go +++ b/github/orgs_personal_access_tokens.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "net/url" + "strconv" "strings" ) @@ -115,6 +116,84 @@ func (s *OrganizationsService) ListFineGrainedPersonalAccessTokens(ctx context.C return pats, resp, nil } +// FineGrainedPersonalAccessTokenRequests represents the details of a request to access organization resources via a fine-grained personal access token. +type FineGrainedPersonalAccessTokenRequests struct { + // Unique identifier of the request for access via fine-grained personal access token. + ID *int64 `json:"id"` + + // Reason is the reason for the request. + Reason *string `json:"reason"` + + // Owner is the GitHub user associated with the token. + Owner *User `json:"owner"` + + // RepositorySelection is the type of repository selection requested. + // Possible values are: "none", "all", "subset". + RepositorySelection *string `json:"repository_selection"` + + // URL to the list of repositories the fine-grained personal access token can access. + // Only follow when `repository_selection` is `subset`. + RepositoriesURL *string `json:"repositories_url"` + + // Permissions are the permissions requested, categorized by type. + Permissions *PersonalAccessTokenPermissions `json:"permissions"` + + // Date and time when the request was created. + CreatedAt *Timestamp `json:"created_at"` + + // Whether the associated fine-grained personal access token has expired. + TokenExpired *bool `json:"token_expired"` + + // Date and time when the associated fine-grained personal access token expires. + TokenExpiresAt *Timestamp `json:"token_expires_at"` + + // TokenID + TokenID *int64 `json:"token_id"` + + // TokenName + TokenName *string `json:"token_name"` + + // Date and time when the associated fine-grained personal access token was last used for authentication. + TokenLastUsedAt *Timestamp `json:"token_last_used_at"` +} + +// ListFineGrainedPATRequestOptions specifies optional parameters to ListFineGrainedPersonalAccessTokenRequests. +type ListFineGrainedPATRequestOptions struct { + // TokenID filters results by the given fine-grained personal access token IDs. + TokenID []int64 `url:"-"` + + ListFineGrainedPATOptions +} + +// ListFineGrainedPersonalAccessTokenRequests lists requests to access organization resources via fine-grained personal access tokens. +// Only GitHub Apps can call this API, using the `Personal access tokens` organization permissions (read). +// +// 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) ([]*FineGrainedPersonalAccessTokenRequests, *Response, error) { + u := fmt.Sprintf("orgs/%v/personal-access-token-requests", org) + // The `owner` parameter is a special case that uses the `owner[]=...` format and needs a custom function to format it correctly. + u, err := addListFineGrainedPATRequestOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, opts) + if err != nil { + return nil, nil, err + } + + var pats []*FineGrainedPersonalAccessTokenRequests + + resp, err := s.client.Do(ctx, req, &pats) + if err != nil { + return nil, resp, err + } + + return pats, resp, nil +} + // ReviewPersonalAccessTokenRequestOptions specifies the parameters to the ReviewPersonalAccessTokenRequest method. type ReviewPersonalAccessTokenRequestOptions struct { Action string `json:"action"` @@ -175,3 +254,54 @@ func addListFineGrainedPATOptions(s string, opts *ListFineGrainedPATOptions) (st return u, nil } + +// addListFineGrainedPATRequestOptions adds the owner and token_id parameters to the URL query string with the correct format if they are set. +// +// GitHub API expects the owner and token_id parameters to be a list of strings in the `owner[]=...` and `token_id[]=...` format. +// For multiple owner and token_id values, the parameters are repeated in the query string. +// +// Example: +// owner[]=user1&owner[]=user2&token_id[]=123&token_id[]=456 +// This will filter the results to only include requests for fine-grained personal access tokens owned by `user1` and `user2` and with token IDs `123` and `456`. +// +// This function ensures the owner and token_id parameters are formatted correctly in the URL query string. +func addListFineGrainedPATRequestOptions(s string, opts *ListFineGrainedPATRequestOptions) (string, error) { + if opts == nil { + return s, nil + } + + u, err := addOptions(s, opts) + if err != nil { + return s, err + } + + if len(opts.Owner) > 0 { + ownerVals := make([]string, len(opts.Owner)) + for i, owner := range opts.Owner { + ownerVals[i] = fmt.Sprintf("owner[]=%v", url.QueryEscape(owner)) + } + ownerQuery := strings.Join(ownerVals, "&") + + if strings.Contains(u, "?") { + u += "&" + ownerQuery + } else { + u += "?" + ownerQuery + } + } + if len(opts.TokenID) > 0 { + tokenIDVals := make([]string, len(opts.TokenID)) + for i, tokenID := range opts.TokenID { + tokenIDVals[i] = fmt.Sprintf("token_id[]=%v", url.QueryEscape(strconv.FormatInt(tokenID, 10))) + } + tokenIDQuery := strings.Join(tokenIDVals, "&") + + if strings.Contains(u, "?") { + u += "&" + tokenIDQuery + } else { + u += "?" + tokenIDQuery + } + return u, nil + } + + return u, nil +} diff --git a/github/orgs_personal_access_tokens_test.go b/github/orgs_personal_access_tokens_test.go index 05cbeaaa0d6..c9a157958b4 100644 --- a/github/orgs_personal_access_tokens_test.go +++ b/github/orgs_personal_access_tokens_test.go @@ -158,6 +158,178 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokens(t *testing.T) }) } +func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/personal-access-token-requests", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + expectedQuery := map[string][]string{ + "per_page": {"2"}, + "page": {"2"}, + "sort": {"created_at"}, + "direction": {"desc"}, + "owner[]": {"octocat", "octodog"}, + "token_id[]": {"11579703", "11579704"}, + } + + query := r.URL.Query() + for key, expectedValues := range expectedQuery { + actualValues := query[key] + if len(actualValues) != len(expectedValues) { + t.Errorf("Expected %v values for query param %v, got %v", len(expectedValues), key, len(actualValues)) + } + for i, expectedValue := range expectedValues { + if actualValues[i] != expectedValue { + t.Errorf("Expected query param %v to be %v, got %v", key, expectedValue, actualValues[i]) + } + } + } + + fmt.Fprint(w, `[ + { + "id": 1848980, + "reason": null, + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "repository_selection": "all", + "repositories_url": "https://api.github.com/organizations/135028681/personal-access-token-requests/1848980/repositories", + "permissions": { + "repository": { + "metadata": "read" + } + }, + "created_at": "2026-02-17T06:49:30Z", + "token_id": 11579703, + "token_name": "testFineGrained", + "token_expired": false, + "token_expires_at": "2026-04-18T06:49:30Z", + "token_last_used_at": null + } + ]`) + }) + + opts := &ListFineGrainedPATRequestOptions{ + ListFineGrainedPATOptions: ListFineGrainedPATOptions{ + ListOptions: ListOptions{Page: 2, PerPage: 2}, + Sort: "created_at", + Direction: "desc", + Owner: []string{"octocat", "octodog"}, + }, + TokenID: []int64{11579703, 11579704}, + } + ctx := t.Context() + requests, resp, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", opts) + if err != nil { + t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests returned error: %v", err) + } + + want := []*FineGrainedPersonalAccessTokenRequests{ + { + ID: Ptr(int64(1848980)), + Reason: nil, + Owner: &User{ + Login: Ptr("octocat"), + ID: Ptr(int64(1)), + NodeID: Ptr("MDQ6VXNlcjE="), + AvatarURL: Ptr("https://github.com/images/error/octocat_happy.gif"), + GravatarID: Ptr(""), + URL: Ptr("https://api.github.com/users/octocat"), + HTMLURL: Ptr("https://github.com/octocat"), + FollowersURL: Ptr("https://api.github.com/users/octocat/followers"), + FollowingURL: Ptr("https://api.github.com/users/octocat/following{/other_user}"), + GistsURL: Ptr("https://api.github.com/users/octocat/gists{/gist_id}"), + StarredURL: Ptr("https://api.github.com/users/octocat/starred{/owner}{/repo}"), + SubscriptionsURL: Ptr("https://api.github.com/users/octocat/subscriptions"), + OrganizationsURL: Ptr("https://api.github.com/users/octocat/orgs"), + ReposURL: Ptr("https://api.github.com/users/octocat/repos"), + EventsURL: Ptr("https://api.github.com/users/octocat/events{/privacy}"), + ReceivedEventsURL: Ptr("https://api.github.com/users/octocat/received_events"), + Type: Ptr("User"), + SiteAdmin: Ptr(false), + }, + RepositorySelection: Ptr("all"), + RepositoriesURL: Ptr("https://api.github.com/organizations/135028681/personal-access-token-requests/1848980/repositories"), + Permissions: &PersonalAccessTokenPermissions{ + Repo: map[string]string{"metadata": "read"}, + }, + CreatedAt: &Timestamp{time.Date(2026, time.February, 17, 6, 49, 30, 0, time.UTC)}, + TokenID: Ptr(int64(11579703)), + TokenName: Ptr("testFineGrained"), + TokenExpired: Ptr(false), + TokenExpiresAt: &Timestamp{time.Date(2026, time.April, 18, 6, 49, 30, 0, time.UTC)}, + TokenLastUsedAt: nil, + }, + } + if !cmp.Equal(requests, want) { + t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests returned %+v, want %+v", requests, want) + } + + if resp == nil { + t.Error("Organizations.ListFineGrainedPersonalAccessTokenRequests returned nil response") + } + + const methodName = "ListFineGrainedPersonalAccessTokenRequests" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "\n", opts) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", opts) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_nilOptions(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/personal-access-token-requests", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + if r.URL.RawQuery != "" { + t.Errorf("Expected no query string when opts is nil, got %q", r.URL.RawQuery) + } + fmt.Fprint(w, "[]") + }) + + ctx := t.Context() + requests, resp, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", nil) + if err != nil { + t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned error: %v", err) + } + if requests == nil { + t.Error("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned nil requests") + } + if len(requests) != 0 { + t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned %v requests, want 0", len(requests)) + } + if resp == nil { + t.Error("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned nil response") + } +} + func TestOrganizationsService_ReviewPersonalAccessTokenRequest(t *testing.T) { t.Parallel() client, mux, _ := setup(t) From f8b7572f6b8be063a994985fe5530eb4267510dc Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 18 Feb 2026 22:57:56 +0530 Subject: [PATCH 2/6] Updated testcases to increase code coverage Signed-off-by: abhishek --- github/orgs_personal_access_tokens_test.go | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/github/orgs_personal_access_tokens_test.go b/github/orgs_personal_access_tokens_test.go index c9a157958b4..ae2badd4b22 100644 --- a/github/orgs_personal_access_tokens_test.go +++ b/github/orgs_personal_access_tokens_test.go @@ -9,6 +9,7 @@ import ( "encoding/json" "fmt" "net/http" + "strings" "testing" "time" @@ -158,6 +159,30 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokens(t *testing.T) }) } +func TestOrganizationsService_ListFineGrainedPersonalAccessTokens_ownerOnly(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/personal-access-tokens", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + // When only Owner is set, addOptions adds no query params, so URL gets "?" + owner[]=... + if !strings.Contains(r.URL.RawQuery, "owner[]=") { + t.Errorf("Expected query to contain owner[]=, got %q", r.URL.RawQuery) + } + if strings.HasPrefix(r.URL.RawQuery, "&") { + t.Errorf("Expected query to start with ?, got %q", r.URL.RawQuery) + } + fmt.Fprint(w, "[]") + }) + + opts := &ListFineGrainedPATOptions{Owner: []string{"octocat"}} + ctx := t.Context() + _, _, err := client.Organizations.ListFineGrainedPersonalAccessTokens(ctx, "o", opts) + if err != nil { + t.Errorf("Organizations.ListFineGrainedPersonalAccessTokens returned error: %v", err) + } +} + func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -330,6 +355,58 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_nilOpti } } +func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_ownerOnly(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/personal-access-token-requests", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + // When only Owner is set (no ListOptions, TokenID, etc.), addOptions adds no query params, so URL gets "?" + owner[]=... + if !strings.Contains(r.URL.RawQuery, "owner[]=") { + t.Errorf("Expected query to contain owner[]=, got %q", r.URL.RawQuery) + } + if strings.HasPrefix(r.URL.RawQuery, "&") { + t.Errorf("Expected query to start with ?, got %q", r.URL.RawQuery) + } + fmt.Fprint(w, "[]") + }) + + opts := &ListFineGrainedPATRequestOptions{ + ListFineGrainedPATOptions: ListFineGrainedPATOptions{Owner: []string{"octocat"}}, + } + ctx := t.Context() + _, _, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", opts) + if err != nil { + t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests returned error: %v", err) + } +} + +func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_tokenIDOnly(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/personal-access-token-requests", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + // When only TokenID is set (no Owner, ListOptions, etc.), addOptions adds no query params, so URL gets "?" + token_id[]=... + if !strings.Contains(r.URL.RawQuery, "token_id[]=") { + t.Errorf("Expected query to contain token_id[]=, got %q", r.URL.RawQuery) + } + if strings.HasPrefix(r.URL.RawQuery, "&") { + t.Errorf("Expected query not to start with & (token_id should be first param with ?), got %q", r.URL.RawQuery) + } + fmt.Fprint(w, "[]") + }) + + opts := &ListFineGrainedPATRequestOptions{ + TokenID: []int64{11579703}, + } + ctx := t.Context() + _, _, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", opts) + if err != nil { + t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests returned error: %v", err) + } +} + func TestOrganizationsService_ReviewPersonalAccessTokenRequest(t *testing.T) { t.Parallel() client, mux, _ := setup(t) From 907d86fc3e10b306348e4677ae3f65946544b204 Mon Sep 17 00:00:00 2001 From: abhishek Date: Fri, 20 Feb 2026 09:47:30 +0530 Subject: [PATCH 3/6] omitempty to the fields Signed-off-by: abhishek --- github/orgs_personal_access_tokens.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/github/orgs_personal_access_tokens.go b/github/orgs_personal_access_tokens.go index 9cf687e6b3e..aa2ac9b51ab 100644 --- a/github/orgs_personal_access_tokens.go +++ b/github/orgs_personal_access_tokens.go @@ -119,42 +119,42 @@ func (s *OrganizationsService) ListFineGrainedPersonalAccessTokens(ctx context.C // FineGrainedPersonalAccessTokenRequests represents the details of a request to access organization resources via a fine-grained personal access token. type FineGrainedPersonalAccessTokenRequests struct { // Unique identifier of the request for access via fine-grained personal access token. - ID *int64 `json:"id"` + ID *int64 `json:"id,omitempty"` // Reason is the reason for the request. - Reason *string `json:"reason"` + Reason *string `json:"reason,omitempty"` // Owner is the GitHub user associated with the token. - Owner *User `json:"owner"` + Owner *User `json:"owner,omitempty"` // RepositorySelection is the type of repository selection requested. // Possible values are: "none", "all", "subset". - RepositorySelection *string `json:"repository_selection"` + RepositorySelection *string `json:"repository_selection,omitempty"` // URL to the list of repositories the fine-grained personal access token can access. // Only follow when `repository_selection` is `subset`. - RepositoriesURL *string `json:"repositories_url"` + RepositoriesURL *string `json:"repositories_url,omitempty"` // Permissions are the permissions requested, categorized by type. - Permissions *PersonalAccessTokenPermissions `json:"permissions"` + Permissions *PersonalAccessTokenPermissions `json:"permissions,omitempty"` // Date and time when the request was created. - CreatedAt *Timestamp `json:"created_at"` + CreatedAt *Timestamp `json:"created_at,omitempty"` // Whether the associated fine-grained personal access token has expired. - TokenExpired *bool `json:"token_expired"` + TokenExpired *bool `json:"token_expired,omitempty"` // Date and time when the associated fine-grained personal access token expires. - TokenExpiresAt *Timestamp `json:"token_expires_at"` + TokenExpiresAt *Timestamp `json:"token_expires_at,omitempty"` // TokenID - TokenID *int64 `json:"token_id"` + TokenID *int64 `json:"token_id,omitempty"` // TokenName - TokenName *string `json:"token_name"` + TokenName *string `json:"token_name,omitempty"` // Date and time when the associated fine-grained personal access token was last used for authentication. - TokenLastUsedAt *Timestamp `json:"token_last_used_at"` + TokenLastUsedAt *Timestamp `json:"token_last_used_at,omitempty"` } // ListFineGrainedPATRequestOptions specifies optional parameters to ListFineGrainedPersonalAccessTokenRequests. From d109c37abee9904d5aa1745c7c520b5edee3bfb6 Mon Sep 17 00:00:00 2001 From: abhishek Date: Fri, 20 Feb 2026 16:11:25 +0530 Subject: [PATCH 4/6] pluralization is removed from structure Signed-off-by: abhishek --- github/github-accessors.go | 24 ++++---- github/github-accessors_test.go | 68 +++++++++++----------- github/github-iterators.go | 4 +- github/github-iterators_test.go | 2 +- github/orgs_personal_access_tokens.go | 8 +-- github/orgs_personal_access_tokens_test.go | 2 +- 6 files changed, 54 insertions(+), 54 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index b6e2951045d..13a4b51af71 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10479,7 +10479,7 @@ func (f *FieldValue) GetProjectNumber() int64 { } // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetCreatedAt() Timestamp { +func (f *FineGrainedPersonalAccessTokenRequest) GetCreatedAt() Timestamp { if f == nil || f.CreatedAt == nil { return Timestamp{} } @@ -10487,7 +10487,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetCreatedAt() Timestamp { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetID() int64 { +func (f *FineGrainedPersonalAccessTokenRequest) GetID() int64 { if f == nil || f.ID == nil { return 0 } @@ -10495,7 +10495,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetID() int64 { } // GetOwner returns the Owner field. -func (f *FineGrainedPersonalAccessTokenRequests) GetOwner() *User { +func (f *FineGrainedPersonalAccessTokenRequest) GetOwner() *User { if f == nil { return nil } @@ -10503,7 +10503,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetOwner() *User { } // GetPermissions returns the Permissions field. -func (f *FineGrainedPersonalAccessTokenRequests) GetPermissions() *PersonalAccessTokenPermissions { +func (f *FineGrainedPersonalAccessTokenRequest) GetPermissions() *PersonalAccessTokenPermissions { if f == nil { return nil } @@ -10511,7 +10511,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetPermissions() *PersonalAcces } // GetReason returns the Reason field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetReason() string { +func (f *FineGrainedPersonalAccessTokenRequest) GetReason() string { if f == nil || f.Reason == nil { return "" } @@ -10519,7 +10519,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetReason() string { } // GetRepositoriesURL returns the RepositoriesURL field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetRepositoriesURL() string { +func (f *FineGrainedPersonalAccessTokenRequest) GetRepositoriesURL() string { if f == nil || f.RepositoriesURL == nil { return "" } @@ -10527,7 +10527,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetRepositoriesURL() string { } // GetRepositorySelection returns the RepositorySelection field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetRepositorySelection() string { +func (f *FineGrainedPersonalAccessTokenRequest) GetRepositorySelection() string { if f == nil || f.RepositorySelection == nil { return "" } @@ -10535,7 +10535,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetRepositorySelection() string } // GetTokenExpired returns the TokenExpired field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetTokenExpired() bool { +func (f *FineGrainedPersonalAccessTokenRequest) GetTokenExpired() bool { if f == nil || f.TokenExpired == nil { return false } @@ -10543,7 +10543,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetTokenExpired() bool { } // GetTokenExpiresAt returns the TokenExpiresAt field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetTokenExpiresAt() Timestamp { +func (f *FineGrainedPersonalAccessTokenRequest) GetTokenExpiresAt() Timestamp { if f == nil || f.TokenExpiresAt == nil { return Timestamp{} } @@ -10551,7 +10551,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetTokenExpiresAt() Timestamp { } // GetTokenID returns the TokenID field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetTokenID() int64 { +func (f *FineGrainedPersonalAccessTokenRequest) GetTokenID() int64 { if f == nil || f.TokenID == nil { return 0 } @@ -10559,7 +10559,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetTokenID() int64 { } // GetTokenLastUsedAt returns the TokenLastUsedAt field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetTokenLastUsedAt() Timestamp { +func (f *FineGrainedPersonalAccessTokenRequest) GetTokenLastUsedAt() Timestamp { if f == nil || f.TokenLastUsedAt == nil { return Timestamp{} } @@ -10567,7 +10567,7 @@ func (f *FineGrainedPersonalAccessTokenRequests) GetTokenLastUsedAt() Timestamp } // GetTokenName returns the TokenName field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequests) GetTokenName() string { +func (f *FineGrainedPersonalAccessTokenRequest) GetTokenName() string { if f == nil || f.TokenName == nil { return "" } diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 20134e5be03..f8944762463 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13614,127 +13614,127 @@ func TestFieldValue_GetProjectNumber(tt *testing.T) { f.GetProjectNumber() } -func TestFineGrainedPersonalAccessTokenRequests_GetCreatedAt(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetCreatedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp - f := &FineGrainedPersonalAccessTokenRequests{CreatedAt: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{CreatedAt: &zeroValue} f.GetCreatedAt() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetCreatedAt() f = nil f.GetCreatedAt() } -func TestFineGrainedPersonalAccessTokenRequests_GetID(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetID(tt *testing.T) { tt.Parallel() var zeroValue int64 - f := &FineGrainedPersonalAccessTokenRequests{ID: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{ID: &zeroValue} f.GetID() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetID() f = nil f.GetID() } -func TestFineGrainedPersonalAccessTokenRequests_GetOwner(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetOwner(tt *testing.T) { tt.Parallel() - f := &FineGrainedPersonalAccessTokenRequests{} + f := &FineGrainedPersonalAccessTokenRequest{} f.GetOwner() f = nil f.GetOwner() } -func TestFineGrainedPersonalAccessTokenRequests_GetPermissions(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetPermissions(tt *testing.T) { tt.Parallel() - f := &FineGrainedPersonalAccessTokenRequests{} + f := &FineGrainedPersonalAccessTokenRequest{} f.GetPermissions() f = nil f.GetPermissions() } -func TestFineGrainedPersonalAccessTokenRequests_GetReason(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetReason(tt *testing.T) { tt.Parallel() var zeroValue string - f := &FineGrainedPersonalAccessTokenRequests{Reason: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{Reason: &zeroValue} f.GetReason() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetReason() f = nil f.GetReason() } -func TestFineGrainedPersonalAccessTokenRequests_GetRepositoriesURL(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetRepositoriesURL(tt *testing.T) { tt.Parallel() var zeroValue string - f := &FineGrainedPersonalAccessTokenRequests{RepositoriesURL: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{RepositoriesURL: &zeroValue} f.GetRepositoriesURL() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetRepositoriesURL() f = nil f.GetRepositoriesURL() } -func TestFineGrainedPersonalAccessTokenRequests_GetRepositorySelection(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetRepositorySelection(tt *testing.T) { tt.Parallel() var zeroValue string - f := &FineGrainedPersonalAccessTokenRequests{RepositorySelection: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{RepositorySelection: &zeroValue} f.GetRepositorySelection() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetRepositorySelection() f = nil f.GetRepositorySelection() } -func TestFineGrainedPersonalAccessTokenRequests_GetTokenExpired(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetTokenExpired(tt *testing.T) { tt.Parallel() var zeroValue bool - f := &FineGrainedPersonalAccessTokenRequests{TokenExpired: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{TokenExpired: &zeroValue} f.GetTokenExpired() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetTokenExpired() f = nil f.GetTokenExpired() } -func TestFineGrainedPersonalAccessTokenRequests_GetTokenExpiresAt(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetTokenExpiresAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp - f := &FineGrainedPersonalAccessTokenRequests{TokenExpiresAt: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{TokenExpiresAt: &zeroValue} f.GetTokenExpiresAt() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetTokenExpiresAt() f = nil f.GetTokenExpiresAt() } -func TestFineGrainedPersonalAccessTokenRequests_GetTokenID(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetTokenID(tt *testing.T) { tt.Parallel() var zeroValue int64 - f := &FineGrainedPersonalAccessTokenRequests{TokenID: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{TokenID: &zeroValue} f.GetTokenID() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetTokenID() f = nil f.GetTokenID() } -func TestFineGrainedPersonalAccessTokenRequests_GetTokenLastUsedAt(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetTokenLastUsedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp - f := &FineGrainedPersonalAccessTokenRequests{TokenLastUsedAt: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{TokenLastUsedAt: &zeroValue} f.GetTokenLastUsedAt() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetTokenLastUsedAt() f = nil f.GetTokenLastUsedAt() } -func TestFineGrainedPersonalAccessTokenRequests_GetTokenName(tt *testing.T) { +func TestFineGrainedPersonalAccessTokenRequest_GetTokenName(tt *testing.T) { tt.Parallel() var zeroValue string - f := &FineGrainedPersonalAccessTokenRequests{TokenName: &zeroValue} + f := &FineGrainedPersonalAccessTokenRequest{TokenName: &zeroValue} f.GetTokenName() - f = &FineGrainedPersonalAccessTokenRequests{} + f = &FineGrainedPersonalAccessTokenRequest{} f.GetTokenName() f = nil f.GetTokenName() diff --git a/github/github-iterators.go b/github/github-iterators.go index ce2e9f8b424..8fc39eeb2d2 100644 --- a/github/github-iterators.go +++ b/github/github-iterators.go @@ -4150,8 +4150,8 @@ func (s *OrganizationsService) ListFailedOrgInvitationsIter(ctx context.Context, } // ListFineGrainedPersonalAccessTokenRequestsIter returns an iterator that paginates through all results of ListFineGrainedPersonalAccessTokenRequests. -func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequestsIter(ctx context.Context, org string, opts *ListFineGrainedPATRequestOptions) iter.Seq2[*FineGrainedPersonalAccessTokenRequests, error] { - return func(yield func(*FineGrainedPersonalAccessTokenRequests, error) bool) { +func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequestsIter(ctx context.Context, org string, opts *ListFineGrainedPATRequestOptions) iter.Seq2[*FineGrainedPersonalAccessTokenRequest, error] { + return func(yield func(*FineGrainedPersonalAccessTokenRequest, error) bool) { // Create a copy of opts to avoid mutating the caller's struct if opts == nil { opts = &ListFineGrainedPATRequestOptions{} diff --git a/github/github-iterators_test.go b/github/github-iterators_test.go index 581a9030bed..872f584f650 100644 --- a/github/github-iterators_test.go +++ b/github/github-iterators_test.go @@ -9147,7 +9147,7 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequestsIter(t * iter = client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter(t.Context(), "", nil) gotItems = 0 - iter(func(item *FineGrainedPersonalAccessTokenRequests, err error) bool { + iter(func(item *FineGrainedPersonalAccessTokenRequest, err error) bool { gotItems++ if err != nil { t.Errorf("Unexpected error: %v", err) diff --git a/github/orgs_personal_access_tokens.go b/github/orgs_personal_access_tokens.go index aa2ac9b51ab..fcdac5df880 100644 --- a/github/orgs_personal_access_tokens.go +++ b/github/orgs_personal_access_tokens.go @@ -116,8 +116,8 @@ func (s *OrganizationsService) ListFineGrainedPersonalAccessTokens(ctx context.C return pats, resp, nil } -// FineGrainedPersonalAccessTokenRequests represents the details of a request to access organization resources via a fine-grained personal access token. -type FineGrainedPersonalAccessTokenRequests struct { +// FineGrainedPersonalAccessTokenRequest represents the details of a request to access organization resources via a fine-grained personal access token. +type FineGrainedPersonalAccessTokenRequest struct { // Unique identifier of the request for access via fine-grained personal access token. ID *int64 `json:"id,omitempty"` @@ -171,7 +171,7 @@ type ListFineGrainedPATRequestOptions struct { // 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) ([]*FineGrainedPersonalAccessTokenRequests, *Response, error) { +func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequests(ctx context.Context, org string, opts *ListFineGrainedPATRequestOptions) ([]*FineGrainedPersonalAccessTokenRequest, *Response, error) { u := fmt.Sprintf("orgs/%v/personal-access-token-requests", org) // The `owner` parameter is a special case that uses the `owner[]=...` format and needs a custom function to format it correctly. u, err := addListFineGrainedPATRequestOptions(u, opts) @@ -184,7 +184,7 @@ func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequests(ctx co return nil, nil, err } - var pats []*FineGrainedPersonalAccessTokenRequests + var pats []*FineGrainedPersonalAccessTokenRequest resp, err := s.client.Do(ctx, req, &pats) if err != nil { diff --git a/github/orgs_personal_access_tokens_test.go b/github/orgs_personal_access_tokens_test.go index ae2badd4b22..8e97d7d3fe4 100644 --- a/github/orgs_personal_access_tokens_test.go +++ b/github/orgs_personal_access_tokens_test.go @@ -267,7 +267,7 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests returned error: %v", err) } - want := []*FineGrainedPersonalAccessTokenRequests{ + want := []*FineGrainedPersonalAccessTokenRequest{ { ID: Ptr(int64(1848980)), Reason: nil, From 86ddc9abc36c73c5fcbf31399925157689c27e37 Mon Sep 17 00:00:00 2001 From: abhishek Date: Mon, 23 Feb 2026 11:55:09 +0530 Subject: [PATCH 5/6] Review comments Signed-off-by: abhishek --- github/github-accessors.go | 72 ----------------- github/github-accessors_test.go | 93 ---------------------- github/github-iterators.go | 4 +- github/github-iterators_test.go | 2 +- github/orgs_personal_access_tokens.go | 86 +++++--------------- github/orgs_personal_access_tokens_test.go | 66 +++++---------- 6 files changed, 43 insertions(+), 280 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 13a4b51af71..63a5dba57e1 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10486,62 +10486,6 @@ func (f *FineGrainedPersonalAccessTokenRequest) GetCreatedAt() Timestamp { return *f.CreatedAt } -// GetID returns the ID field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequest) GetID() int64 { - if f == nil || f.ID == nil { - return 0 - } - return *f.ID -} - -// GetOwner returns the Owner field. -func (f *FineGrainedPersonalAccessTokenRequest) GetOwner() *User { - if f == nil { - return nil - } - return f.Owner -} - -// GetPermissions returns the Permissions field. -func (f *FineGrainedPersonalAccessTokenRequest) GetPermissions() *PersonalAccessTokenPermissions { - if f == nil { - return nil - } - return f.Permissions -} - -// GetReason returns the Reason field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequest) GetReason() string { - if f == nil || f.Reason == nil { - return "" - } - return *f.Reason -} - -// GetRepositoriesURL returns the RepositoriesURL field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequest) GetRepositoriesURL() string { - if f == nil || f.RepositoriesURL == nil { - return "" - } - return *f.RepositoriesURL -} - -// GetRepositorySelection returns the RepositorySelection field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequest) GetRepositorySelection() string { - if f == nil || f.RepositorySelection == nil { - return "" - } - return *f.RepositorySelection -} - -// GetTokenExpired returns the TokenExpired field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequest) GetTokenExpired() bool { - if f == nil || f.TokenExpired == nil { - return false - } - return *f.TokenExpired -} - // GetTokenExpiresAt returns the TokenExpiresAt field if it's non-nil, zero value otherwise. func (f *FineGrainedPersonalAccessTokenRequest) GetTokenExpiresAt() Timestamp { if f == nil || f.TokenExpiresAt == nil { @@ -10550,14 +10494,6 @@ func (f *FineGrainedPersonalAccessTokenRequest) GetTokenExpiresAt() Timestamp { return *f.TokenExpiresAt } -// GetTokenID returns the TokenID field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequest) GetTokenID() int64 { - if f == nil || f.TokenID == nil { - return 0 - } - return *f.TokenID -} - // GetTokenLastUsedAt returns the TokenLastUsedAt field if it's non-nil, zero value otherwise. func (f *FineGrainedPersonalAccessTokenRequest) GetTokenLastUsedAt() Timestamp { if f == nil || f.TokenLastUsedAt == nil { @@ -10566,14 +10502,6 @@ func (f *FineGrainedPersonalAccessTokenRequest) GetTokenLastUsedAt() Timestamp { return *f.TokenLastUsedAt } -// GetTokenName returns the TokenName field if it's non-nil, zero value otherwise. -func (f *FineGrainedPersonalAccessTokenRequest) GetTokenName() string { - if f == nil || f.TokenName == nil { - return "" - } - return *f.TokenName -} - // GetIdentifier returns the Identifier field if it's non-nil, zero value otherwise. func (f *FirstPatchedVersion) GetIdentifier() string { if f == nil || f.Identifier == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index f8944762463..b6909553416 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13625,77 +13625,6 @@ func TestFineGrainedPersonalAccessTokenRequest_GetCreatedAt(tt *testing.T) { f.GetCreatedAt() } -func TestFineGrainedPersonalAccessTokenRequest_GetID(tt *testing.T) { - tt.Parallel() - var zeroValue int64 - f := &FineGrainedPersonalAccessTokenRequest{ID: &zeroValue} - f.GetID() - f = &FineGrainedPersonalAccessTokenRequest{} - f.GetID() - f = nil - f.GetID() -} - -func TestFineGrainedPersonalAccessTokenRequest_GetOwner(tt *testing.T) { - tt.Parallel() - f := &FineGrainedPersonalAccessTokenRequest{} - f.GetOwner() - f = nil - f.GetOwner() -} - -func TestFineGrainedPersonalAccessTokenRequest_GetPermissions(tt *testing.T) { - tt.Parallel() - f := &FineGrainedPersonalAccessTokenRequest{} - f.GetPermissions() - f = nil - f.GetPermissions() -} - -func TestFineGrainedPersonalAccessTokenRequest_GetReason(tt *testing.T) { - tt.Parallel() - var zeroValue string - f := &FineGrainedPersonalAccessTokenRequest{Reason: &zeroValue} - f.GetReason() - f = &FineGrainedPersonalAccessTokenRequest{} - f.GetReason() - f = nil - f.GetReason() -} - -func TestFineGrainedPersonalAccessTokenRequest_GetRepositoriesURL(tt *testing.T) { - tt.Parallel() - var zeroValue string - f := &FineGrainedPersonalAccessTokenRequest{RepositoriesURL: &zeroValue} - f.GetRepositoriesURL() - f = &FineGrainedPersonalAccessTokenRequest{} - f.GetRepositoriesURL() - f = nil - f.GetRepositoriesURL() -} - -func TestFineGrainedPersonalAccessTokenRequest_GetRepositorySelection(tt *testing.T) { - tt.Parallel() - var zeroValue string - f := &FineGrainedPersonalAccessTokenRequest{RepositorySelection: &zeroValue} - f.GetRepositorySelection() - f = &FineGrainedPersonalAccessTokenRequest{} - f.GetRepositorySelection() - f = nil - f.GetRepositorySelection() -} - -func TestFineGrainedPersonalAccessTokenRequest_GetTokenExpired(tt *testing.T) { - tt.Parallel() - var zeroValue bool - f := &FineGrainedPersonalAccessTokenRequest{TokenExpired: &zeroValue} - f.GetTokenExpired() - f = &FineGrainedPersonalAccessTokenRequest{} - f.GetTokenExpired() - f = nil - f.GetTokenExpired() -} - func TestFineGrainedPersonalAccessTokenRequest_GetTokenExpiresAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp @@ -13707,17 +13636,6 @@ func TestFineGrainedPersonalAccessTokenRequest_GetTokenExpiresAt(tt *testing.T) f.GetTokenExpiresAt() } -func TestFineGrainedPersonalAccessTokenRequest_GetTokenID(tt *testing.T) { - tt.Parallel() - var zeroValue int64 - f := &FineGrainedPersonalAccessTokenRequest{TokenID: &zeroValue} - f.GetTokenID() - f = &FineGrainedPersonalAccessTokenRequest{} - f.GetTokenID() - f = nil - f.GetTokenID() -} - func TestFineGrainedPersonalAccessTokenRequest_GetTokenLastUsedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp @@ -13729,17 +13647,6 @@ func TestFineGrainedPersonalAccessTokenRequest_GetTokenLastUsedAt(tt *testing.T) f.GetTokenLastUsedAt() } -func TestFineGrainedPersonalAccessTokenRequest_GetTokenName(tt *testing.T) { - tt.Parallel() - var zeroValue string - f := &FineGrainedPersonalAccessTokenRequest{TokenName: &zeroValue} - f.GetTokenName() - f = &FineGrainedPersonalAccessTokenRequest{} - f.GetTokenName() - f = nil - f.GetTokenName() -} - func TestFirstPatchedVersion_GetIdentifier(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-iterators.go b/github/github-iterators.go index 8fc39eeb2d2..96a0c7b37e1 100644 --- a/github/github-iterators.go +++ b/github/github-iterators.go @@ -4150,11 +4150,11 @@ func (s *OrganizationsService) ListFailedOrgInvitationsIter(ctx context.Context, } // ListFineGrainedPersonalAccessTokenRequestsIter returns an iterator that paginates through all results of ListFineGrainedPersonalAccessTokenRequests. -func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequestsIter(ctx context.Context, org string, opts *ListFineGrainedPATRequestOptions) iter.Seq2[*FineGrainedPersonalAccessTokenRequest, error] { +func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequestsIter(ctx context.Context, org string, opts *ListFineGrainedPATOptions) iter.Seq2[*FineGrainedPersonalAccessTokenRequest, error] { return func(yield func(*FineGrainedPersonalAccessTokenRequest, error) bool) { // Create a copy of opts to avoid mutating the caller's struct if opts == nil { - opts = &ListFineGrainedPATRequestOptions{} + opts = &ListFineGrainedPATOptions{} } else { opts = Ptr(*opts) } diff --git a/github/github-iterators_test.go b/github/github-iterators_test.go index 872f584f650..c1d44bca2dc 100644 --- a/github/github-iterators_test.go +++ b/github/github-iterators_test.go @@ -9120,7 +9120,7 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequestsIter(t * t.Errorf("client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter call 1 got %v items; want %v", gotItems, want) } - opts := &ListFineGrainedPATRequestOptions{} + opts := &ListFineGrainedPATOptions{} iter = client.Organizations.ListFineGrainedPersonalAccessTokenRequestsIter(t.Context(), "", opts) gotItems = 0 for _, err := range iter { diff --git a/github/orgs_personal_access_tokens.go b/github/orgs_personal_access_tokens.go index fcdac5df880..5c08a2eeb02 100644 --- a/github/orgs_personal_access_tokens.go +++ b/github/orgs_personal_access_tokens.go @@ -84,6 +84,9 @@ type ListFineGrainedPATOptions struct { // This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. LastUsedAfter string `url:"last_used_after,omitempty"` + // TokenID filters results by the given fine-grained personal access token IDs. + TokenID []int64 `url:"-"` + ListOptions } @@ -119,50 +122,42 @@ func (s *OrganizationsService) ListFineGrainedPersonalAccessTokens(ctx context.C // FineGrainedPersonalAccessTokenRequest represents the details of a request to access organization resources via a fine-grained personal access token. type FineGrainedPersonalAccessTokenRequest struct { // Unique identifier of the request for access via fine-grained personal access token. - ID *int64 `json:"id,omitempty"` + ID int64 `json:"id"` // Reason is the reason for the request. - Reason *string `json:"reason,omitempty"` + Reason string `json:"reason"` // Owner is the GitHub user associated with the token. - Owner *User `json:"owner,omitempty"` + Owner User `json:"owner"` // RepositorySelection is the type of repository selection requested. // Possible values are: "none", "all", "subset". - RepositorySelection *string `json:"repository_selection,omitempty"` + RepositorySelection string `json:"repository_selection"` // URL to the list of repositories the fine-grained personal access token can access. // Only follow when `repository_selection` is `subset`. - RepositoriesURL *string `json:"repositories_url,omitempty"` + RepositoriesURL string `json:"repositories_url"` // Permissions are the permissions requested, categorized by type. - Permissions *PersonalAccessTokenPermissions `json:"permissions,omitempty"` + Permissions PersonalAccessTokenPermissions `json:"permissions"` // Date and time when the request was created. - CreatedAt *Timestamp `json:"created_at,omitempty"` + CreatedAt *Timestamp `json:"created_at"` // Whether the associated fine-grained personal access token has expired. - TokenExpired *bool `json:"token_expired,omitempty"` + TokenExpired bool `json:"token_expired"` // Date and time when the associated fine-grained personal access token expires. - TokenExpiresAt *Timestamp `json:"token_expires_at,omitempty"` + TokenExpiresAt *Timestamp `json:"token_expires_at"` // TokenID - TokenID *int64 `json:"token_id,omitempty"` + TokenID int64 `json:"token_id"` // TokenName - TokenName *string `json:"token_name,omitempty"` + TokenName string `json:"token_name"` // Date and time when the associated fine-grained personal access token was last used for authentication. - TokenLastUsedAt *Timestamp `json:"token_last_used_at,omitempty"` -} - -// ListFineGrainedPATRequestOptions specifies optional parameters to ListFineGrainedPersonalAccessTokenRequests. -type ListFineGrainedPATRequestOptions struct { - // TokenID filters results by the given fine-grained personal access token IDs. - TokenID []int64 `url:"-"` - - ListFineGrainedPATOptions + TokenLastUsedAt *Timestamp `json:"token_last_used_at"` } // ListFineGrainedPersonalAccessTokenRequests lists requests to access organization resources via fine-grained personal access tokens. @@ -171,10 +166,10 @@ type ListFineGrainedPATRequestOptions struct { // 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) { +func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequests(ctx context.Context, org string, opts *ListFineGrainedPATOptions) ([]*FineGrainedPersonalAccessTokenRequest, *Response, error) { u := fmt.Sprintf("orgs/%v/personal-access-token-requests", org) // The `owner` parameter is a special case that uses the `owner[]=...` format and needs a custom function to format it correctly. - u, err := addListFineGrainedPATRequestOptions(u, opts) + u, err := addListFineGrainedPATOptions(u, opts) if err != nil { return nil, nil, err } @@ -218,16 +213,16 @@ func (s *OrganizationsService) ReviewPersonalAccessTokenRequest(ctx context.Cont return s.client.Do(ctx, req, nil) } -// addListFineGrainedPATOptions adds the owner parameter to the URL query string with the correct format if it is set. +// addListFineGrainedPATOptions adds the owner and token_id parameters to the URL query string with the correct format if they are set. // // GitHub API expects the owner parameter to be a list of strings in the `owner[]=...` format. -// For multiple owner values, the owner parameter is repeated in the query string. +// For multiple owner and token_id values, the owner and token_id parameters are repeated in the query string. // // Example: -// owner[]=user1&owner[]=user2 -// This will filter the results to only include fine-grained personal access tokens owned by `user1` and `user2`. +// owner[]=user1&owner[]=user2&token_id[]=123&token_id[]=456 +// This will filter the results to only include fine-grained personal access tokens owned by `user1` and `user2` and with token IDs `123` and `456`. // -// This function ensures the owner parameter is formatted correctly in the URL query string. +// This function ensures the owner and token_id parameters are formatted correctly in the URL query string. func addListFineGrainedPATOptions(s string, opts *ListFineGrainedPATOptions) (string, error) { u, err := addOptions(s, opts) if err != nil { @@ -238,43 +233,6 @@ func addListFineGrainedPATOptions(s string, opts *ListFineGrainedPATOptions) (st return "", errors.New("opts must be provided") } - if len(opts.Owner) > 0 { - ownerVals := make([]string, len(opts.Owner)) - for i, owner := range opts.Owner { - ownerVals[i] = fmt.Sprintf("owner[]=%v", url.QueryEscape(owner)) - } - ownerQuery := strings.Join(ownerVals, "&") - - if strings.Contains(u, "?") { - u += "&" + ownerQuery - } else { - u += "?" + ownerQuery - } - } - - return u, nil -} - -// addListFineGrainedPATRequestOptions adds the owner and token_id parameters to the URL query string with the correct format if they are set. -// -// GitHub API expects the owner and token_id parameters to be a list of strings in the `owner[]=...` and `token_id[]=...` format. -// For multiple owner and token_id values, the parameters are repeated in the query string. -// -// Example: -// owner[]=user1&owner[]=user2&token_id[]=123&token_id[]=456 -// This will filter the results to only include requests for fine-grained personal access tokens owned by `user1` and `user2` and with token IDs `123` and `456`. -// -// This function ensures the owner and token_id parameters are formatted correctly in the URL query string. -func addListFineGrainedPATRequestOptions(s string, opts *ListFineGrainedPATRequestOptions) (string, error) { - if opts == nil { - return s, nil - } - - u, err := addOptions(s, opts) - if err != nil { - return s, err - } - if len(opts.Owner) > 0 { ownerVals := make([]string, len(opts.Owner)) for i, owner := range opts.Owner { diff --git a/github/orgs_personal_access_tokens_test.go b/github/orgs_personal_access_tokens_test.go index 8e97d7d3fe4..760e83c2457 100644 --- a/github/orgs_personal_access_tokens_test.go +++ b/github/orgs_personal_access_tokens_test.go @@ -252,14 +252,12 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test ]`) }) - opts := &ListFineGrainedPATRequestOptions{ - ListFineGrainedPATOptions: ListFineGrainedPATOptions{ - ListOptions: ListOptions{Page: 2, PerPage: 2}, - Sort: "created_at", - Direction: "desc", - Owner: []string{"octocat", "octodog"}, - }, - TokenID: []int64{11579703, 11579704}, + opts := &ListFineGrainedPATOptions{ + ListOptions: ListOptions{Page: 2, PerPage: 2}, + Sort: "created_at", + Direction: "desc", + Owner: []string{"octocat", "octodog"}, + TokenID: []int64{11579703, 11579704}, } ctx := t.Context() requests, resp, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", opts) @@ -269,9 +267,9 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test want := []*FineGrainedPersonalAccessTokenRequest{ { - ID: Ptr(int64(1848980)), - Reason: nil, - Owner: &User{ + ID: 1848980, + Reason: "", + Owner: User{ Login: Ptr("octocat"), ID: Ptr(int64(1)), NodeID: Ptr("MDQ6VXNlcjE="), @@ -291,15 +289,15 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test Type: Ptr("User"), SiteAdmin: Ptr(false), }, - RepositorySelection: Ptr("all"), - RepositoriesURL: Ptr("https://api.github.com/organizations/135028681/personal-access-token-requests/1848980/repositories"), - Permissions: &PersonalAccessTokenPermissions{ + RepositorySelection: "all", + RepositoriesURL: "https://api.github.com/organizations/135028681/personal-access-token-requests/1848980/repositories", + Permissions: PersonalAccessTokenPermissions{ Repo: map[string]string{"metadata": "read"}, }, CreatedAt: &Timestamp{time.Date(2026, time.February, 17, 6, 49, 30, 0, time.UTC)}, - TokenID: Ptr(int64(11579703)), - TokenName: Ptr("testFineGrained"), - TokenExpired: Ptr(false), + TokenID: 11579703, + TokenName: "testFineGrained", + TokenExpired: false, TokenExpiresAt: &Timestamp{time.Date(2026, time.April, 18, 6, 49, 30, 0, time.UTC)}, TokenLastUsedAt: nil, }, @@ -327,34 +325,6 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests(t *test }) } -func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_nilOptions(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/orgs/o/personal-access-token-requests", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - if r.URL.RawQuery != "" { - t.Errorf("Expected no query string when opts is nil, got %q", r.URL.RawQuery) - } - fmt.Fprint(w, "[]") - }) - - ctx := t.Context() - requests, resp, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", nil) - if err != nil { - t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned error: %v", err) - } - if requests == nil { - t.Error("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned nil requests") - } - if len(requests) != 0 { - t.Errorf("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned %v requests, want 0", len(requests)) - } - if resp == nil { - t.Error("Organizations.ListFineGrainedPersonalAccessTokenRequests with nil opts returned nil response") - } -} - func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_ownerOnly(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -371,8 +341,8 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_ownerOn fmt.Fprint(w, "[]") }) - opts := &ListFineGrainedPATRequestOptions{ - ListFineGrainedPATOptions: ListFineGrainedPATOptions{Owner: []string{"octocat"}}, + opts := &ListFineGrainedPATOptions{ + Owner: []string{"octocat"}, } ctx := t.Context() _, _, err := client.Organizations.ListFineGrainedPersonalAccessTokenRequests(ctx, "o", opts) @@ -397,7 +367,7 @@ func TestOrganizationsService_ListFineGrainedPersonalAccessTokenRequests_tokenID fmt.Fprint(w, "[]") }) - opts := &ListFineGrainedPATRequestOptions{ + opts := &ListFineGrainedPATOptions{ TokenID: []int64{11579703}, } ctx := t.Context() From 8bb130d51c98f84b8c8d878e57cfec046cbbe407 Mon Sep 17 00:00:00 2001 From: abhishek Date: Mon, 23 Feb 2026 12:03:23 +0530 Subject: [PATCH 6/6] Empty line Signed-off-by: abhishek --- github/orgs_personal_access_tokens.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/orgs_personal_access_tokens.go b/github/orgs_personal_access_tokens.go index 5c08a2eeb02..f09b436c12a 100644 --- a/github/orgs_personal_access_tokens.go +++ b/github/orgs_personal_access_tokens.go @@ -180,7 +180,6 @@ func (s *OrganizationsService) ListFineGrainedPersonalAccessTokenRequests(ctx co } var pats []*FineGrainedPersonalAccessTokenRequest - resp, err := s.client.Do(ctx, req, &pats) if err != nil { return nil, resp, err