Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scanning validity checks #3026

Merged
1 change: 1 addition & 0 deletions github/enterprise_code_security_and_analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type EnterpriseSecurityAnalysisSettings struct {
SecretScanningEnabledForNewRepositories *bool `json:"secret_scanning_enabled_for_new_repositories,omitempty"`
SecretScanningPushProtectionEnabledForNewRepositories *bool `json:"secret_scanning_push_protection_enabled_for_new_repositories,omitempty"`
SecretScanningPushProtectionCustomLink *string `json:"secret_scanning_push_protection_custom_link,omitempty"`
SecretScanningValidityChecksEnabled *bool `json:"secret_scanning_validity_checks_enabled,omitempty"`
}

// GetCodeSecurityAndAnalysis gets code security and analysis features for an enterprise.
Expand Down
5 changes: 4 additions & 1 deletion github/enterprise_code_security_and_analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func TestEnterpriseService_GetCodeSecurityAndAnalysis(t *testing.T) {
"advanced_security_enabled_for_new_repositories": true,
"secret_scanning_enabled_for_new_repositories": true,
"secret_scanning_push_protection_enabled_for_new_repositories": true,
"secret_scanning_push_protection_custom_link": "https://github.com/test-org/test-repo/blob/main/README.md"
"secret_scanning_push_protection_custom_link": "https://github.com/test-org/test-repo/blob/main/README.md",
"secret_scanning_validity_checks_enabled": true
}`)
})

Expand All @@ -44,6 +45,7 @@ func TestEnterpriseService_GetCodeSecurityAndAnalysis(t *testing.T) {
SecretScanningEnabledForNewRepositories: Bool(true),
SecretScanningPushProtectionEnabledForNewRepositories: Bool(true),
SecretScanningPushProtectionCustomLink: String("https://github.com/test-org/test-repo/blob/main/README.md"),
SecretScanningValidityChecksEnabled: Bool(true),
}

if !cmp.Equal(settings, want) {
Expand Down Expand Up @@ -73,6 +75,7 @@ func TestEnterpriseService_UpdateCodeSecurityAndAnalysis(t *testing.T) {
SecretScanningEnabledForNewRepositories: Bool(true),
SecretScanningPushProtectionEnabledForNewRepositories: Bool(true),
SecretScanningPushProtectionCustomLink: String("https://github.com/test-org/test-repo/blob/main/README.md"),
SecretScanningValidityChecksEnabled: Bool(true),
}

mux.HandleFunc("/enterprises/e/code_security_and_analysis", func(w http.ResponseWriter, r *http.Request) {
Expand Down
32 changes: 32 additions & 0 deletions github/github-accessors.go

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

37 changes: 37 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.

20 changes: 11 additions & 9 deletions github/github-stringify_test.go

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

2 changes: 2 additions & 0 deletions github/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type Organization struct {
SecretScanningEnabledForNewRepos *bool `json:"secret_scanning_enabled_for_new_repositories,omitempty"`
// SecretScanningPushProtectionEnabledForNewRepos toggles whether secret scanning push protection is enabled on new repositories.
SecretScanningPushProtectionEnabledForNewRepos *bool `json:"secret_scanning_push_protection_enabled_for_new_repositories,omitempty"`
// SecretScanningValidityChecksEnabled toggles whether secret scanning validity check is enabled.
SecretScanningValidityChecksEnabled *bool `json:"secret_scanning_validity_checks_enabled,omitempty"`

// API URLs
URL *string `json:"url,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ type SecurityAndAnalysis struct {
SecretScanning *SecretScanning `json:"secret_scanning,omitempty"`
SecretScanningPushProtection *SecretScanningPushProtection `json:"secret_scanning_push_protection,omitempty"`
DependabotSecurityUpdates *DependabotSecurityUpdates `json:"dependabot_security_updates,omitempty"`
SecretScanningValidityChecks *SecretScanningValidityChecks `json:"secret_scanning_validity_checks,omitempty"`
}

func (s SecurityAndAnalysis) String() string {
Expand Down Expand Up @@ -248,6 +249,13 @@ func (d DependabotSecurityUpdates) String() string {
return Stringify(d)
}

// SecretScanningValidityChecks represents the state of secret scanning validity checks on a repository.
//
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-security-and-analysis-settings-for-your-repository#allowing-validity-checks-for-partner-patterns-in-a-repository
type SecretScanningValidityChecks struct {
Status *string `json:"status,omitempty"`
}

// List calls either RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser
// depending on whether user is empty.
//
Expand Down
4 changes: 2 additions & 2 deletions github/repos_test.go
Original file line number Diff line number Diff line change
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"},"secret_scanning_push_protection":{"status":"enabled"},"dependabot_security_updates":{"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"}, "secret_scanning_validity_checks":{"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")}, SecretScanningPushProtection: &SecretScanningPushProtection{String("enabled")}, DependabotSecurityUpdates: &DependabotSecurityUpdates{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")}, SecretScanningValidityChecks: &SecretScanningValidityChecks{String("enabled")}}}
if !cmp.Equal(got, want) {
t.Errorf("Repositories.Get returned %+v, want %+v", got, want)
}
Expand Down
Loading