Repository: google/go-github
Pull request #2934 (2023-09-19 00:47:15)

Fix SecretScanning API by switching arguments from url to json
Closes: #2871.

This PR fixes the endpoint:
https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning/secret-scanning#update-a-secret-scanning-alert
by sending its parameters in the body instead of as URL query parameters.

I was unable to edit #2871 directly, so this is a replacement.
Thank you, @jentfoo for the bug report and initial PR!

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/2934?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2934](https://app.codecov.io/gh/google/go-github/pull/2934?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (bad4743) into [master](https://app.codecov.io/gh/google/go-github/commit/0e8dfaeabef7bb709e2cf06fbf24c99d6a3bce1f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (0e8dfae) will **not change** coverage.
> Report is 1 commits behind head on master.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2934   +/-   ##
=======================================
  Coverage   98.17%   98.17%           
=======================================
  Files         143      143           
  Lines       12597    12597           
=======================================
  Hits        12367    12367           
  Misses        156      156           
  Partials       74       74           
```


| [Files Changed](https://app.codecov.io/gh/google/go-github/pull/2934?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/secret\_scanning.go](https://app.codecov.io/gh/google/go-github/pull/2934?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3NlY3JldF9zY2FubmluZy5nbw==) | `100.00% <ø> (ø)` | |


gmlewis: Awaiting LGTM+Approval from any other contributor to this repo before merging.
jentfoo: Thank you for the help in fixing this @gmlewis!
gmlewis: > Thank you for the help in fixing this @gmlewis!

My pleasure.  Thank you, @jentfoo for the bug report and your help tracking down the problem!
Would you mind giving an LGTM+Approval so I can merge this?
gmlewis: Thank you, @jentfoo !
Merging.

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index e7cfa86f..083d6139 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -20958,22 +20958,6 @@ func (s *SecretScanningAlertUpdateOptions) GetResolution() string {
 	return *s.Resolution
 }
 
-// GetSecretType returns the SecretType field if it's non-nil, zero value otherwise.
-func (s *SecretScanningAlertUpdateOptions) GetSecretType() string {
-	if s == nil || s.SecretType == nil {
-		return ""
-	}
-	return *s.SecretType
-}
-
-// GetState returns the State field if it's non-nil, zero value otherwise.
-func (s *SecretScanningAlertUpdateOptions) GetState() string {
-	if s == nil || s.State == nil {
-		return ""
-	}
-	return *s.State
-}
-
 // GetStatus returns the Status field if it's non-nil, zero value otherwise.
 func (s *SecretScanningPushProtection) GetStatus() string {
 	if s == nil || s.Status == nil {
diff --git a/github/secret_scanning.go b/github/secret_scanning.go
index bea3f0e7..30d3da8e 100644
--- a/github/secret_scanning.go
+++ b/github/secret_scanning.go
@@ -80,16 +80,14 @@ type SecretScanningAlertListOptions struct {
 
 // SecretScanningAlertUpdateOptions specifies optional parameters to the SecretScanningService.UpdateAlert method.
 type SecretScanningAlertUpdateOptions struct {
-	// Required. Sets the state of the secret scanning alert. Can be either open or resolved.
-	// You must provide resolution when you set the state to resolved.
-	State *string `url:"state,omitempty"`
-
-	// A comma-separated list of secret types to return. By default all secret types are returned.
-	SecretType *string `url:"secret_type,omitempty"`
-
-	// Required when the state is resolved. The reason for resolving the alert. Can be one of false_positive,
-	// wont_fix, revoked, or used_in_tests.
-	Resolution *string `url:"resolution,omitempty"`
+	// State is required and sets the state of the secret scanning alert.
+	// Can be either "open" or "resolved".
+	// You must provide resolution when you set the state to "resolved".
+	State string `json:"state"`
+
+	// Required when the state is "resolved" and represents the reason for resolving the alert.
+	// Can be one of: "false_positive", "wont_fix", "revoked", or "used_in_tests".
+	Resolution *string `json:"resolution,omitempty"`
 }
 
 // Lists secret scanning alerts for eligible repositories in an enterprise, from newest to oldest.


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index e2918bea..90d15369 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -24440,26 +24440,6 @@ func TestSecretScanningAlertUpdateOptions_GetResolution(tt *testing.T) {
 	s.GetResolution()
 }
 
-func TestSecretScanningAlertUpdateOptions_GetSecretType(tt *testing.T) {
-	var zeroValue string
-	s := &SecretScanningAlertUpdateOptions{SecretType: &zeroValue}
-	s.GetSecretType()
-	s = &SecretScanningAlertUpdateOptions{}
-	s.GetSecretType()
-	s = nil
-	s.GetSecretType()
-}
-
-func TestSecretScanningAlertUpdateOptions_GetState(tt *testing.T) {
-	var zeroValue string
-	s := &SecretScanningAlertUpdateOptions{State: &zeroValue}
-	s.GetState()
-	s = &SecretScanningAlertUpdateOptions{}
-	s.GetState()
-	s = nil
-	s.GetState()
-}
-
 func TestSecretScanningPushProtection_GetStatus(tt *testing.T) {
 	var zeroValue string
 	s := &SecretScanningPushProtection{Status: &zeroValue}
diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go
index 2ca439aa..7898d29a 100644
--- a/github/secret_scanning_test.go
+++ b/github/secret_scanning_test.go
@@ -359,7 +359,7 @@ func TestSecretScanningService_UpdateAlert(t *testing.T) {
 		v := new(SecretScanningAlertUpdateOptions)
 		assertNilError(t, json.NewDecoder(r.Body).Decode(v))
 
-		want := &SecretScanningAlertUpdateOptions{State: String("resolved"), Resolution: String("used_in_tests")}
+		want := &SecretScanningAlertUpdateOptions{State: "resolved", Resolution: String("used_in_tests")}
 
 		if !cmp.Equal(v, want) {
 			t.Errorf("Request body = %+v, want %+v", v, want)
@@ -381,7 +381,7 @@ func TestSecretScanningService_UpdateAlert(t *testing.T) {
 	})
 
 	ctx := context.Background()
-	opts := &SecretScanningAlertUpdateOptions{State: String("resolved"), Resolution: String("used_in_tests")}
+	opts := &SecretScanningAlertUpdateOptions{State: "resolved", Resolution: String("used_in_tests")}
 
 	alert, _, err := client.SecretScanning.UpdateAlert(ctx, "o", "r", 1, opts)
 	if err != nil {