Repository: google/go-github
Pull request #3270 (2024-09-17 18:57:53)

feat!: Add login query param support to ListCredentialAuthorizations
BREAKING CHANGE: `ListCredentialAuthorizations` now takes `opts *CredentialAuthorizationsListOptions` instead of `ListOptions`.

As per the docs for the [List SAML SSO authorizations for an organization](https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#list-saml-sso-authorizations-for-an-organization) endpoint — it supports a query param named `login` to filter the authorizations by a github user.

This PR adds support for passing this `login` query param via a new struct (`CredentialAuthorizationsListOptions`) which embeds `ListOptions` as `ListOptions` itself only supports `Page` and `PerPage` query params.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3270?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 92.94%. Comparing base [(`2b8c7fa`)](https://app.codecov.io/gh/google/go-github/commit/2b8c7fa86fcd1cb4a89a44c8e7b5a49fe4be8a45?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) to head [(`86ea809`)](https://app.codecov.io/gh/google/go-github/commit/86ea809d3408b3186ffbf6606f09ff38da9092ef?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 112 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #3270      +/-   ##
==========================================
- Coverage   97.72%   92.94%   -4.78%     
==========================================
  Files         153      171      +18     
  Lines       13390    11669    -1721     
==========================================
- Hits        13085    10846    -2239     
- Misses        215      729     +514     
- Partials       90       94       +4     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3270?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

zeusdeux: Thanks for the quick review @gmlewis! Accepted your suggestion! 
zeusdeux: @gmlewis should I tag someone as a second reviewer?
gmlewis: > @gmlewis should I tag someone as a second reviewer?

Since this repo is maintained strictly by volunteers, I try to not tag individuals to respect their time unless there is an urgent need.
Having said that, please feel free to perform code reviews on any PRs that have been labeled "NeedsReview".
zeusdeux: Sounds good @gmlewis! Thank you for the information. 
Btw, re: failing build — any notes on the codecov/project failure? Not sure if I should take that into account given the test change in this PR covers the new code path. 🙏🏽 
gmlewis: > Btw, re: failing build — any notes on the codecov/project failure? Not sure if I should take that into account given the test change in this PR covers the new code path. 🙏🏽

Unfortunately, you can ignore the Codecov report, as we are waiting for #3221 to be addressed by @google-admin and update this repo's Codecov authentication token so that our reports will be useful.

zeusdeux: Makes sense. Does that mean that this PR only needs one more ✅ and it'll be good to land? 
And if so, what's the release process? Thanks for all the help so far @gmlewis! 🙏🏽 
gmlewis: > Does that mean that this PR only needs one more ✅ and it'll be good to land?

Yes, and it is now ready to merge. Thank you, @alexef !

> And if so, what's the release process? 

We cut a new release about once per month, so the next release should be in three to four weeks. 

Merging.




Patch:
diff --git a/github/orgs_credential_authorizations.go b/github/orgs_credential_authorizations.go
index eed0f0c6..dca42433 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 {


Test patch:
diff --git a/github/orgs_credential_authorizations_test.go b/github/orgs_credential_authorizations_test.go
index e3986eb5..006ee86c 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",
@@ -34,7 +34,11 @@ func TestOrganizationsService_ListCredentialAuthorizations(t *testing.T) {
 		]`)
 	})
 
-	opts := &ListOptions{Page: 2, PerPage: 2}
+	opts := &CredentialAuthorizationsListOptions{
+		ListOptions: ListOptions{Page: 2, PerPage: 2},
+		Login:       "l",
+	}
+
 	ctx := context.Background()
 	creds, _, err := client.Organizations.ListCredentialAuthorizations(ctx, "o", opts)
 	if err != nil {