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

Code before:

	// Unique string to distinguish the credential.
	// Only included in responses with credential_type of SSH Key.
	Fingerprint *string `json:"fingerprint,omitempty"`

	AuthorizedCredentialID *int64 `json:"authorized_credential_id,omitempty"`

	// The title given to the ssh key.
	// This will only be present when the credential is an ssh key.
	AuthorizedCredentialTitle *string `json:"authorized_credential_title,omitempty"`

	// The note given to the token.
	// This will only be present when the credential is a token.
	AuthorizedCredentialNote *string `json:"authorized_credential_note,omitempty"`

	// The expiry for the token.
	// This will only be present when the credential is a token.
	AuthorizedCredentialExpiresAt *Timestamp `json:"authorized_credential_expires_at,omitempty"`
}

// CredentialAuthorizationsListOptions adds the Login option as supported by the
// list SAML SSO authorizations for organizations endpoint alongside paging options
// such as Page and PerPage
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/orgs#list-saml-sso-authorizations-for-an-organization
type CredentialAuthorizationsListOptions struct {
	ListOptions
	// For credentials authorizations for an organization, limit the list of authorizations to a specific login (aka github username)
	Login string `url:"login,omitempty"`
}

// ListCredentialAuthorizations lists credentials authorized through SAML SSO
// for a given organization. Only available with GitHub Enterprise Cloud.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/orgs#list-saml-sso-authorizations-for-an-organization
//
//meta:operation GET /orgs/{org}/credential-authorizations
func (s *OrganizationsService) ListCredentialAuthorizations(ctx context.Context, org string, opts *CredentialAuthorizationsListOptions) ([]*CredentialAuthorization, *Response, error) {
	u := fmt.Sprintf("orgs/%v/credential-authorizations", org)
	u, err := addOptions(u, opts)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest(http.MethodGet, u, nil)
	if err != nil {
		return nil, nil, err
	}

	var creds []*CredentialAuthorization
	resp, err := s.client.Do(ctx, req, &creds)
	if err != nil {

Review comment (suggestion):
Chose to embed `ListOptions` instead of extending it as it is reused for other `List*` functions which don't necessarily support the `login` query parameter.

Code after:

	// Unique string to distinguish the credential.
	// Only included in responses with credential_type of SSH Key.
	Fingerprint *string `json:"fingerprint,omitempty"`

	AuthorizedCredentialID *int64 `json:"authorized_credential_id,omitempty"`

	// The title given to the ssh key.
	// This will only be present when the credential is an ssh key.
	AuthorizedCredentialTitle *string `json:"authorized_credential_title,omitempty"`

	// The note given to the token.
	// This will only be present when the credential is a token.
	AuthorizedCredentialNote *string `json:"authorized_credential_note,omitempty"`

	// The expiry for the token.
	// This will only be present when the credential is a token.
	AuthorizedCredentialExpiresAt *Timestamp `json:"authorized_credential_expires_at,omitempty"`
}

// CredentialAuthorizationsListOptions adds the Login option as supported by the
// list SAML SSO authorizations for organizations endpoint alongside paging options
// such as Page and PerPage.
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/orgs#list-saml-sso-authorizations-for-an-organization
type CredentialAuthorizationsListOptions struct {
	ListOptions
	// For credentials authorizations for an organization, limit the list of authorizations to a specific login (aka github username)
	Login string `url:"login,omitempty"`
}

// ListCredentialAuthorizations lists credentials authorized through SAML SSO
// for a given organization. Only available with GitHub Enterprise Cloud.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/orgs#list-saml-sso-authorizations-for-an-organization
//
//meta:operation GET /orgs/{org}/credential-authorizations
func (s *OrganizationsService) ListCredentialAuthorizations(ctx context.Context, org string, opts *CredentialAuthorizationsListOptions) ([]*CredentialAuthorization, *Response, error) {
	u := fmt.Sprintf("orgs/%v/credential-authorizations", org)
	u, err := addOptions(u, opts)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest(http.MethodGet, u, nil)
	if err != nil {
		return nil, nil, err
	}

	var creds []*CredentialAuthorization
	resp, err := s.client.Do(ctx, req, &creds)
	if err != nil {