From 86ea809d3408b3186ffbf6606f09ff38da9092ef Mon Sep 17 00:00:00 2001 From: Mudit Ameta Date: Tue, 17 Sep 2024 20:53:49 +0200 Subject: [PATCH 1/3] feat: Add login query param support to ListCredentialAuthorizations --- github/orgs_credential_authorizations.go | 12 +++++++++++- github/orgs_credential_authorizations_test.go | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/github/orgs_credential_authorizations.go b/github/orgs_credential_authorizations.go index eed0f0c66e0..65629369b2e 100644 --- a/github/orgs_credential_authorizations.go +++ b/github/orgs_credential_authorizations.go @@ -55,13 +55,23 @@ type CredentialAuthorization struct { 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 *ListOptions) ([]*CredentialAuthorization, *Response, error) { +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 { diff --git a/github/orgs_credential_authorizations_test.go b/github/orgs_credential_authorizations_test.go index e3986eb5ca2..cdafe5b1270 100644 --- a/github/orgs_credential_authorizations_test.go +++ b/github/orgs_credential_authorizations_test.go @@ -34,7 +34,10 @@ func TestOrganizationsService_ListCredentialAuthorizations(t *testing.T) { ]`) }) - opts := &ListOptions{Page: 2, PerPage: 2} + opts := &CredentialAuthorizationsListOptions{ + ListOptions: ListOptions{Page: 2, PerPage: 2}, + } + ctx := context.Background() creds, _, err := client.Organizations.ListCredentialAuthorizations(ctx, "o", opts) if err != nil { From 77824d0e02a4bee62cb6961c1b6df7f51b450d6f Mon Sep 17 00:00:00 2001 From: Mudit Date: Tue, 17 Sep 2024 21:23:50 +0200 Subject: [PATCH 2/3] Add missing full stop in the docs Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/orgs_credential_authorizations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/orgs_credential_authorizations.go b/github/orgs_credential_authorizations.go index 65629369b2e..dca42433c30 100644 --- a/github/orgs_credential_authorizations.go +++ b/github/orgs_credential_authorizations.go @@ -57,7 +57,7 @@ type CredentialAuthorization struct { // CredentialAuthorizationsListOptions adds the Login option as supported by the // list SAML SSO authorizations for organizations endpoint alongside paging options -// such as Page and PerPage +// 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 From c849e6fd1fdd1b90ebcd395df5149bc54a7f91d3 Mon Sep 17 00:00:00 2001 From: Mudit Ameta Date: Wed, 18 Sep 2024 15:11:30 +0200 Subject: [PATCH 3/3] Update unit test --- github/orgs_credential_authorizations_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github/orgs_credential_authorizations_test.go b/github/orgs_credential_authorizations_test.go index cdafe5b1270..006ee86c45c 100644 --- a/github/orgs_credential_authorizations_test.go +++ b/github/orgs_credential_authorizations_test.go @@ -21,7 +21,7 @@ func TestOrganizationsService_ListCredentialAuthorizations(t *testing.T) { mux.HandleFunc("/orgs/o/credential-authorizations", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodGet) - testFormValues(t, r, values{"per_page": "2", "page": "2"}) + testFormValues(t, r, values{"per_page": "2", "page": "2", "login": "l"}) fmt.Fprint(w, `[ { "login": "l", @@ -36,6 +36,7 @@ func TestOrganizationsService_ListCredentialAuthorizations(t *testing.T) { opts := &CredentialAuthorizationsListOptions{ ListOptions: ListOptions{Page: 2, PerPage: 2}, + Login: "l", } ctx := context.Background()