Skip to content

Commit 97cd4d6

Browse files
authored
feat: Add CodeSecurity to SecurityAndAnalysis (#4155)
1 parent cf3388c commit 97cd4d6

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

github/event_types_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18215,6 +18215,9 @@ func TestSecurityAndAnalysisEvent_Marshal(t *testing.T) {
1821518215
DependabotSecurityUpdates: &DependabotSecurityUpdates{
1821618216
Status: Ptr("enabled"),
1821718217
},
18218+
CodeSecurity: &CodeSecurity{
18219+
Status: Ptr("enabled"),
18220+
},
1821818221
},
1821918222
},
1822018223
},
@@ -18377,6 +18380,9 @@ func TestSecurityAndAnalysisEvent_Marshal(t *testing.T) {
1837718380
},
1837818381
"dependabot_security_updates": {
1837918382
"status": "enabled"
18383+
},
18384+
"code_security": {
18385+
"status": "enabled"
1838018386
}
1838118387
}
1838218388
}

github/github-accessors.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-stringify_test.go

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ type SecurityAndAnalysis struct {
200200
SecretScanningPushProtection *SecretScanningPushProtection `json:"secret_scanning_push_protection,omitempty"`
201201
DependabotSecurityUpdates *DependabotSecurityUpdates `json:"dependabot_security_updates,omitempty"`
202202
SecretScanningValidityChecks *SecretScanningValidityChecks `json:"secret_scanning_validity_checks,omitempty"`
203+
CodeSecurity *CodeSecurity `json:"code_security,omitempty"`
203204
}
204205

205206
// RepositoryPermissions represents the permissions a user has for a repository.
@@ -266,6 +267,17 @@ type SecretScanningValidityChecks struct {
266267
Status *string `json:"status,omitempty"`
267268
}
268269

270+
// CodeSecurity represents the state of code security on a repository.
271+
//
272+
// GitHub API docs: https://docs.github.com/en/code-security/getting-started/github-security-features#available-with-github-code-security
273+
type CodeSecurity struct {
274+
Status *string `json:"status,omitempty"`
275+
}
276+
277+
func (c CodeSecurity) String() string {
278+
return Stringify(c)
279+
}
280+
269281
// List calls either RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser
270282
// depending on whether user is empty.
271283
//

github/repos_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func TestRepositoriesService_Get(t *testing.T) {
411411
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
412412
testMethod(t, r, "GET")
413413
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
414-
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"}}}`)
414+
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"}, "code_security":{"status":"enabled"}}}`)
415415
})
416416

417417
ctx := t.Context()
@@ -420,7 +420,7 @@ func TestRepositoriesService_Get(t *testing.T) {
420420
t.Errorf("Repositories.Get returned error: %v", err)
421421
}
422422

423-
want := &Repository{ID: Ptr(int64(1)), Name: Ptr("n"), Description: Ptr("d"), Owner: &User{Login: Ptr("l")}, License: &License{Key: Ptr("mit")}, SecurityAndAnalysis: &SecurityAndAnalysis{AdvancedSecurity: &AdvancedSecurity{Status: Ptr("enabled")}, SecretScanning: &SecretScanning{Ptr("enabled")}, SecretScanningPushProtection: &SecretScanningPushProtection{Ptr("enabled")}, DependabotSecurityUpdates: &DependabotSecurityUpdates{Ptr("enabled")}, SecretScanningValidityChecks: &SecretScanningValidityChecks{Ptr("enabled")}}}
423+
want := &Repository{ID: Ptr(int64(1)), Name: Ptr("n"), Description: Ptr("d"), Owner: &User{Login: Ptr("l")}, License: &License{Key: Ptr("mit")}, SecurityAndAnalysis: &SecurityAndAnalysis{AdvancedSecurity: &AdvancedSecurity{Status: Ptr("enabled")}, SecretScanning: &SecretScanning{Ptr("enabled")}, SecretScanningPushProtection: &SecretScanningPushProtection{Ptr("enabled")}, DependabotSecurityUpdates: &DependabotSecurityUpdates{Ptr("enabled")}, SecretScanningValidityChecks: &SecretScanningValidityChecks{Ptr("enabled")}, CodeSecurity: &CodeSecurity{Ptr("enabled")}}}
424424
if !cmp.Equal(got, want) {
425425
t.Errorf("Repositories.Get returned %+v, want %+v", got, want)
426426
}

0 commit comments

Comments
 (0)