Skip to content

Commit

Permalink
Add SecretScanningPushProtection field to SecurityAndAnalysis struct (#…
Browse files Browse the repository at this point in the history
…2476)

Fixes: #2475.
  • Loading branch information
kuhlman-labs committed Sep 22, 2022
1 parent 182338c commit 8a4bdb5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
16 changes: 16 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions github/repos.go
Expand Up @@ -205,8 +205,9 @@ type RepositoryListOptions struct {
// SecurityAndAnalysis specifies the optional advanced security features
// that are enabled on a given repository.
type SecurityAndAnalysis struct {
AdvancedSecurity *AdvancedSecurity `json:"advanced_security,omitempty"`
SecretScanning *SecretScanning `json:"secret_scanning,omitempty"`
AdvancedSecurity *AdvancedSecurity `json:"advanced_security,omitempty"`
SecretScanning *SecretScanning `json:"secret_scanning,omitempty"`
SecretScanningPushProtection *SecretScanningPushProtection `json:"secret_scanning_push_protection,omitempty"`
}

func (s SecurityAndAnalysis) String() string {
Expand Down Expand Up @@ -235,6 +236,13 @@ func (s SecretScanning) String() string {
return Stringify(s)
}

// SecretScanningPushProtection specifies the state of secret scanning push protection on a repository.
//
// GitHub API docs: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning#about-secret-scanning-for-partner-patterns
type SecretScanningPushProtection struct {
Status *string `json:"status,omitempty"`
}

// List the repositories for a user. Passing the empty string will list
// repositories for the authenticated user.
//
Expand Down
4 changes: 2 additions & 2 deletions github/repos_test.go
Expand Up @@ -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"}}}`)
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"}}}`)
})

ctx := context.Background()
Expand All @@ -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")}}}
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")}}}
if !cmp.Equal(got, want) {
t.Errorf("Repositories.Get returned %+v, want %+v", got, want)
}
Expand Down

0 comments on commit 8a4bdb5

Please sign in to comment.