Repository: google/go-github
File: github/orgs_personal_access_tokens.go (Go)

Code before:

	// Date and time when the request was created.
	CreatedAt *Timestamp `json:"created_at,omitempty"`

	// Whether the associated fine-grained personal access token has 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,omitempty"`

	// TokenID
	TokenID *int64 `json:"token_id,omitempty"`

	// TokenName
	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,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
}

// 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) ([]*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)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, opts)
	if err != nil {
		return nil, nil, err
	}

	var pats []*FineGrainedPersonalAccessTokenRequest

	resp, err := s.client.Do(ctx, req, &pats)
	if err != nil {

Review comment (suggestion):
`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`.

Code after:

	// 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"`
}

// 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 *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 := addListFineGrainedPATOptions(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 []*FineGrainedPersonalAccessTokenRequest
	resp, err := s.client.Do(ctx, req, &pats)
	if err != nil {
		return nil, resp, err
	}

	return pats, resp, nil
}