From dc78e50c40a0e3c5f74b3fbf076ecc3b5ca6232a Mon Sep 17 00:00:00 2001 From: Emil Vaagland Date: Wed, 28 Jun 2023 22:28:37 +0200 Subject: [PATCH] Add support for getting Repository when listing secret scanning alerts for Enterprise There is no easy way of getting the org/repo when listing secret scanning alerts for enterprise in the current struct. The API returns the Repository, and with this change it will be included in the SecretScanningAlert --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 7 +++++++ github/secret_scanning.go | 23 ++++++++++++----------- github/secret_scanning_test.go | 12 +++++++++++- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 01b5796fec..41cd582c1a 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -19510,6 +19510,14 @@ func (s *SecretScanningAlert) GetNumber() int { return *s.Number } +// GetRepository returns the Repository field. +func (s *SecretScanningAlert) GetRepository() *Repository { + if s == nil { + return nil + } + return s.Repository +} + // GetResolution returns the Resolution field if it's non-nil, zero value otherwise. func (s *SecretScanningAlert) GetResolution() string { if s == nil || s.Resolution == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 959edc4deb..993a12484b 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -22792,6 +22792,13 @@ func TestSecretScanningAlert_GetNumber(tt *testing.T) { s.GetNumber() } +func TestSecretScanningAlert_GetRepository(tt *testing.T) { + s := &SecretScanningAlert{} + s.GetRepository() + s = nil + s.GetRepository() +} + func TestSecretScanningAlert_GetResolution(tt *testing.T) { var zeroValue string s := &SecretScanningAlert{Resolution: &zeroValue} diff --git a/github/secret_scanning.go b/github/secret_scanning.go index d512560d9f..36ad555377 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -16,17 +16,18 @@ type SecretScanningService service // SecretScanningAlert represents a GitHub secret scanning alert. type SecretScanningAlert struct { - Number *int `json:"number,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - LocationsURL *string `json:"locations_url,omitempty"` - State *string `json:"state,omitempty"` - Resolution *string `json:"resolution,omitempty"` - ResolvedAt *Timestamp `json:"resolved_at,omitempty"` - ResolvedBy *User `json:"resolved_by,omitempty"` - SecretType *string `json:"secret_type,omitempty"` - Secret *string `json:"secret,omitempty"` + Number *int `json:"number,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + LocationsURL *string `json:"locations_url,omitempty"` + State *string `json:"state,omitempty"` + Resolution *string `json:"resolution,omitempty"` + ResolvedAt *Timestamp `json:"resolved_at,omitempty"` + ResolvedBy *User `json:"resolved_by,omitempty"` + SecretType *string `json:"secret_type,omitempty"` + Secret *string `json:"secret,omitempty"` + Repository *Repository `json:"repository,omitempty"` } // SecretScanningAlertLocation represents the location for a secret scanning alert. diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index 69cd7d3fef..7527591338 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -35,7 +35,12 @@ func TestSecretScanningService_ListAlertsForEnterprise(t *testing.T) { "resolved_at": null, "resolved_by": null, "secret_type": "mailchimp_api_key", - "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2" + "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2", + "repository": { + "id": 1, + "name": "n", + "url": "url" + } }]`) }) @@ -61,6 +66,11 @@ func TestSecretScanningService_ListAlertsForEnterprise(t *testing.T) { ResolvedBy: nil, SecretType: String("mailchimp_api_key"), Secret: String("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), + Repository: &Repository{ + ID: Int64(1), + URL: String("url"), + Name: String("n"), + }, }, }