From 4039a9fdb9ad9e8ef14dd80213bba4c055492cbc Mon Sep 17 00:00:00 2001 From: Jarek Porzucek <17789797+jporzucek@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:08:41 +0200 Subject: [PATCH 1/2] Add Dependabot field in security_and_analysis --- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 17 +++++++++++++++++ github/github-stringify_test.go | 23 ++++++++++++++++++++++- github/repos.go | 16 ++++++++++++++++ github/repos_test.go | 4 ++-- 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 35e61043ab8..4b954aaa0ed 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 29d1fd4f1a5..a0c7f766931 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 0ad7eefa342..a8a7b6f0b14 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 5ffad6dd3c4..bf4232a1f72 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"` } 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 b35f44ddc30..70321fd7c1c 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) } From 54e630606fea56381c44bfaa3aab3df3a1a22a6f Mon Sep 17 00:00:00 2001 From: Jarek Porzucek <17789797+jporzucek@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:59:01 +0200 Subject: [PATCH 2/2] Add missing omitempty Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/repos.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos.go b/github/repos.go index bf4232a1f72..2451ed43689 100644 --- a/github/repos.go +++ b/github/repos.go @@ -210,7 +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"` + DependabotSecurityUpdates *DependabotSecurityUpdates `json:"dependabot_security_updates,omitempty"` } func (s SecurityAndAnalysis) String() string {