diff --git a/github/github-accessors.go b/github/github-accessors.go index 35e61043ab..4b954aaa0e 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4966,6 +4966,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 { @@ -20126,6 +20134,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/github-accessors_test.go b/github/github-accessors_test.go index 29d1fd4f1a..a0c7f76693 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -5851,6 +5851,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} @@ -23475,6 +23485,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 0ad7eefa34..a8a7b6f0b1 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.go b/github/repos.go index 5ffad6dd3c..2451ed4368 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. // diff --git a/github/repos_test.go b/github/repos_test.go index b35f44ddc3..70321fd7c1 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) }