Repository: google/go-github
Pull request #2846 (2023-07-26 11:00:05)

Add Dependabot field in security_and_analysis
Fixes https://github.com/google/go-github/issues/2845

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/2846?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2846](https://app.codecov.io/gh/google/go-github/pull/2846?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (4039a9f) into [master](https://app.codecov.io/gh/google/go-github/commit/c030d43bc8e3003715a3de91972b1a594039d262?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (c030d43) will **increase** coverage by `0.00%`.
> Report is 3 commits behind head on master.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master    #2846   +/-   ##
=======================================
  Coverage   98.06%   98.06%           
=======================================
  Files         137      138    +1     
  Lines       12291    12318   +27     
=======================================
+ Hits        12053    12080   +27     
  Misses        162      162           
  Partials       76       76           
```


| [Files Changed](https://app.codecov.io/gh/google/go-github/pull/2846?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/repos.go](https://app.codecov.io/gh/google/go-github/pull/2846?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3JlcG9zLmdv) | `98.84% <100.00%> (+<0.01%)` | :arrow_up: |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/google/go-github/pull/2846/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)



Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 4dd5529a..e8d4e1ac 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -5054,6 +5054,14 @@ func (d *DependabotSecurityAdvisory) GetWithdrawnAt() Timestamp {
 	return *d.WithdrawnAt
 }
 
+// GetStatus returns the Status field if it's non-nil, zero value otherwise.
+func (d *DependabotSecurityUpdates) GetStatus() string {
+	if d == nil || d.Status == nil {
+		return ""
+	}
+	return *d.Status
+}
+
 // GetManifestPath returns the ManifestPath field if it's non-nil, zero value otherwise.
 func (d *Dependency) GetManifestPath() string {
 	if d == nil || d.ManifestPath == nil {
@@ -20214,6 +20222,14 @@ func (s *SecurityAndAnalysis) GetAdvancedSecurity() *AdvancedSecurity {
 	return s.AdvancedSecurity
 }
 
+// GetDependabotSecurityUpdates returns the DependabotSecurityUpdates field.
+func (s *SecurityAndAnalysis) GetDependabotSecurityUpdates() *DependabotSecurityUpdates {
+	if s == nil {
+		return nil
+	}
+	return s.DependabotSecurityUpdates
+}
+
 // GetSecretScanning returns the SecretScanning field.
 func (s *SecurityAndAnalysis) GetSecretScanning() *SecretScanning {
 	if s == nil {
diff --git a/github/repos.go b/github/repos.go
index 5ffad6dd..2451ed43 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -210,6 +210,7 @@ type SecurityAndAnalysis struct {
 	AdvancedSecurity             *AdvancedSecurity             `json:"advanced_security,omitempty"`
 	SecretScanning               *SecretScanning               `json:"secret_scanning,omitempty"`
 	SecretScanningPushProtection *SecretScanningPushProtection `json:"secret_scanning_push_protection,omitempty"`
+	DependabotSecurityUpdates    *DependabotSecurityUpdates    `json:"dependabot_security_updates,omitempty"`
 }
 
 func (s SecurityAndAnalysis) String() string {
@@ -245,6 +246,21 @@ type SecretScanningPushProtection struct {
 	Status *string `json:"status,omitempty"`
 }
 
+func (s SecretScanningPushProtection) String() string {
+	return Stringify(s)
+}
+
+// DependabotSecurityUpdates specifies the state of Dependabot security updates on a repository.
+//
+// GitHub API docs: https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates
+type DependabotSecurityUpdates struct {
+	Status *string `json:"status,omitempty"`
+}
+
+func (d DependabotSecurityUpdates) String() string {
+	return Stringify(d)
+}
+
 // List the repositories for a user. Passing the empty string will list
 // repositories for the authenticated user.
 //


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 75148227..2385aeb0 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -5961,6 +5961,16 @@ func TestDependabotSecurityAdvisory_GetWithdrawnAt(tt *testing.T) {
 	d.GetWithdrawnAt()
 }
 
+func TestDependabotSecurityUpdates_GetStatus(tt *testing.T) {
+	var zeroValue string
+	d := &DependabotSecurityUpdates{Status: &zeroValue}
+	d.GetStatus()
+	d = &DependabotSecurityUpdates{}
+	d.GetStatus()
+	d = nil
+	d.GetStatus()
+}
+
 func TestDependency_GetManifestPath(tt *testing.T) {
 	var zeroValue string
 	d := &Dependency{ManifestPath: &zeroValue}
@@ -23585,6 +23595,13 @@ func TestSecurityAndAnalysis_GetAdvancedSecurity(tt *testing.T) {
 	s.GetAdvancedSecurity()
 }
 
+func TestSecurityAndAnalysis_GetDependabotSecurityUpdates(tt *testing.T) {
+	s := &SecurityAndAnalysis{}
+	s.GetDependabotSecurityUpdates()
+	s = nil
+	s.GetDependabotSecurityUpdates()
+}
+
 func TestSecurityAndAnalysis_GetSecretScanning(tt *testing.T) {
 	s := &SecurityAndAnalysis{}
 	s.GetSecretScanning()
diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go
index 0ad7eefa..a8a7b6f0 100644
--- a/github/github-stringify_test.go
+++ b/github/github-stringify_test.go
@@ -342,6 +342,16 @@ func TestContributorStats_String(t *testing.T) {
 	}
 }
 
+func TestDependabotSecurityUpdates_String(t *testing.T) {
+	v := DependabotSecurityUpdates{
+		Status: String(""),
+	}
+	want := `github.DependabotSecurityUpdates{Status:""}`
+	if got := v.String(); got != want {
+		t.Errorf("DependabotSecurityUpdates.String = %v, want %v", got, want)
+	}
+}
+
 func TestDiscussionComment_String(t *testing.T) {
 	v := DiscussionComment{
 		Author:        &User{},
@@ -1776,13 +1786,24 @@ func TestSecretScanning_String(t *testing.T) {
 	}
 }
 
+func TestSecretScanningPushProtection_String(t *testing.T) {
+	v := SecretScanningPushProtection{
+		Status: String(""),
+	}
+	want := `github.SecretScanningPushProtection{Status:""}`
+	if got := v.String(); got != want {
+		t.Errorf("SecretScanningPushProtection.String = %v, want %v", got, want)
+	}
+}
+
 func TestSecurityAndAnalysis_String(t *testing.T) {
 	v := SecurityAndAnalysis{
 		AdvancedSecurity:             &AdvancedSecurity{},
 		SecretScanning:               &SecretScanning{},
 		SecretScanningPushProtection: &SecretScanningPushProtection{},
+		DependabotSecurityUpdates:    &DependabotSecurityUpdates{},
 	}
-	want := `github.SecurityAndAnalysis{AdvancedSecurity:github.AdvancedSecurity{}, SecretScanning:github.SecretScanning{}, SecretScanningPushProtection:github.SecretScanningPushProtection{}}`
+	want := `github.SecurityAndAnalysis{AdvancedSecurity:github.AdvancedSecurity{}, SecretScanning:github.SecretScanning{}, SecretScanningPushProtection:github.SecretScanningPushProtection{}, DependabotSecurityUpdates:github.DependabotSecurityUpdates{}}`
 	if got := v.String(); got != want {
 		t.Errorf("SecurityAndAnalysis.String = %v, want %v", got, want)
 	}
diff --git a/github/repos_test.go b/github/repos_test.go
index b35f44dd..70321fd7 100644
--- a/github/repos_test.go
+++ b/github/repos_test.go
@@ -360,7 +360,7 @@ func TestRepositoriesService_Get(t *testing.T) {
 	mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
-		fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"},"security_and_analysis":{"advanced_security":{"status":"enabled"},"secret_scanning":{"status":"enabled"},"secret_scanning_push_protection":{"status":"enabled"}}}`)
+		fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"},"security_and_analysis":{"advanced_security":{"status":"enabled"},"secret_scanning":{"status":"enabled"},"secret_scanning_push_protection":{"status":"enabled"},"dependabot_security_updates":{"status": "enabled"}}}`)
 	})
 
 	ctx := context.Background()
@@ -369,7 +369,7 @@ func TestRepositoriesService_Get(t *testing.T) {
 		t.Errorf("Repositories.Get returned error: %v", err)
 	}
 
-	want := &Repository{ID: Int64(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}, SecurityAndAnalysis: &SecurityAndAnalysis{AdvancedSecurity: &AdvancedSecurity{Status: String("enabled")}, SecretScanning: &SecretScanning{String("enabled")}, SecretScanningPushProtection: &SecretScanningPushProtection{String("enabled")}}}
+	want := &Repository{ID: Int64(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}, SecurityAndAnalysis: &SecurityAndAnalysis{AdvancedSecurity: &AdvancedSecurity{Status: String("enabled")}, SecretScanning: &SecretScanning{String("enabled")}, SecretScanningPushProtection: &SecretScanningPushProtection{String("enabled")}, DependabotSecurityUpdates: &DependabotSecurityUpdates{String("enabled")}}}
 	if !cmp.Equal(got, want) {
 		t.Errorf("Repositories.Get returned %+v, want %+v", got, want)
 	}