From f97ab6d16b0a3907555bb3b2847a1c758c4fb3af Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 05:47:32 +0530 Subject: [PATCH 01/11] add PushProtectionBypasses and ScanHistory in secret scanning endpoints --- github/github-accessors.go | 24 +++++++ github/github-accessors_test.go | 33 +++++++++ github/secret_scanning.go | 85 ++++++++++++++++++++++ github/secret_scanning_test.go | 123 ++++++++++++++++++++++++++++++++ 4 files changed, 265 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index d0973b280b0..6ce96f908f2 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -20870,6 +20870,14 @@ func (p *PushEventRepository) GetWatchersCount() int { return *p.WatchersCount } +// GetExpireAt returns the ExpireAt field if it's non-nil, zero value otherwise. +func (p *PushProtectionBypass) GetExpireAt() time.Time { + if p == nil || p.ExpireAt == nil { + return time.Time{} + } + return *p.ExpireAt +} + // GetActionsRunnerRegistration returns the ActionsRunnerRegistration field. func (r *RateLimits) GetActionsRunnerRegistration() *Rate { if r == nil { @@ -24838,6 +24846,22 @@ func (s *SBOMInfo) GetSPDXVersion() string { return *s.SPDXVersion } +// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. +func (s *Scan) GetCompletedAt() time.Time { + if s == nil || s.CompletedAt == nil { + return time.Time{} + } + return *s.CompletedAt +} + +// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise. +func (s *Scan) GetStartedAt() time.Time { + if s == nil || s.StartedAt == nil { + return time.Time{} + } + return *s.StartedAt +} + // GetAnalysisKey returns the AnalysisKey field if it's non-nil, zero value otherwise. func (s *ScanningAnalysis) GetAnalysisKey() string { if s == nil || s.AnalysisKey == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index dbc78f046ba..26cec196947 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -26925,6 +26925,17 @@ func TestPushEventRepository_GetWatchersCount(tt *testing.T) { p.GetWatchersCount() } +func TestPushProtectionBypass_GetExpireAt(tt *testing.T) { + tt.Parallel() + var zeroValue time.Time + p := &PushProtectionBypass{ExpireAt: &zeroValue} + p.GetExpireAt() + p = &PushProtectionBypass{} + p.GetExpireAt() + p = nil + p.GetExpireAt() +} + func TestRateLimits_GetActionsRunnerRegistration(tt *testing.T) { tt.Parallel() r := &RateLimits{} @@ -31991,6 +32002,28 @@ func TestSBOMInfo_GetSPDXVersion(tt *testing.T) { s.GetSPDXVersion() } +func TestScan_GetCompletedAt(tt *testing.T) { + tt.Parallel() + var zeroValue time.Time + s := &Scan{CompletedAt: &zeroValue} + s.GetCompletedAt() + s = &Scan{} + s.GetCompletedAt() + s = nil + s.GetCompletedAt() +} + +func TestScan_GetStartedAt(tt *testing.T) { + tt.Parallel() + var zeroValue time.Time + s := &Scan{StartedAt: &zeroValue} + s.GetStartedAt() + s = &Scan{} + s.GetStartedAt() + s = nil + s.GetStartedAt() +} + func TestScanningAnalysis_GetAnalysisKey(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/secret_scanning.go b/github/secret_scanning.go index f75800f6e0b..9fe0196790b 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "time" ) // SecretScanningService handles communication with the secret scanning related @@ -120,6 +121,42 @@ type SecretScanningAlertUpdateOptions struct { ResolutionComment *string `json:"resolution_comment,omitempty"` } +// CreatePushProtectionBypass represents the parameters for PushProtectionBypasses. +type CreatePushProtectionBypass struct { + Reason string `json:"reason"` + PlaceholderID string `json:"placeholder_id"` +} + +// PushProtectionBypass represents the responses from PushProtectionBypasses. +type PushProtectionBypass struct { + Reason string `json:"reason"` + ExpireAt *time.Time `json:"expire_at"` + TokenType string `json:"token_type"` +} + +// Scan represents the common fields for a secret scanning scan. +type Scan struct { + Type string `json:"type"` + Status string `json:"status"` + CompletedAt *time.Time `json:"completed_at"` + StartedAt *time.Time `json:"started_at"` +} + +// CustomPatternScan represents a scan with an associated custom pattern. +type CustomPatternScan struct { + Scan + PatternSlug string `json:"pattern_slug,omitempty"` + PatternScope string `json:"pattern_scope,omitempty"` +} + +// SecretScanningResponse is the top-level struct for the secret scanning API response. +type SecretScanningResponse struct { + IncrementalScans []*Scan `json:"incremental_scans"` + BackfillScans []*Scan `json:"backfill_scans"` + PatternUpdateScans []*Scan `json:"pattern_update_scans"` + CustomPatternBackfills []*CustomPatternScan `json:"custom_pattern_backfill_scans"` +} + // ListAlertsForEnterprise lists secret scanning alerts for eligible repositories in an enterprise, from newest to oldest. // // To use this endpoint, you must be a member of the enterprise, and you must use an access token with the repo scope or @@ -285,3 +322,51 @@ func (s *SecretScanningService) ListLocationsForAlert(ctx context.Context, owner return locations, resp, nil } + +// PushProtectionBypasses creates a push protection bypass for a given repository. +// +// To use this endpoint, you must be an administrator for the repository or organization, and you must use an access token with +// the repo scope or security_events scope. +// +// GitHub API docs: https://docs.github.com/rest/secret-scanning/secret-scanning#create-a-push-protection-bypass +// +//meta:operation POST /repos/{owner}/{repo}/secret-scanning/push-protection-bypasses +func (s *SecretScanningService) PushProtectionBypasses(ctx context.Context, owner, repo string, opts *CreatePushProtectionBypass) (*PushProtectionBypass, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/secret-scanning/push-protection-bypasses", owner, repo) + + req, err := s.client.NewRequest("POST", u, opts) + if err != nil { + return nil, nil, err + } + var reponsePushProtectionBypass *PushProtectionBypass + resp, err := s.client.Do(ctx, req, &reponsePushProtectionBypass) + if err != nil { + return nil, resp, err + } + return reponsePushProtectionBypass, resp, nil +} + +// ScanHistory fetches the secret scanning history for a given repository. +// +// To use this endpoint, you must be an administrator for the repository or organization, and you must use an access token with +// the repo scope or security_events scope and gitHub advanced security or secret scanning must be enabled. +// +// GitHub API docs: https://docs.github.com/rest/secret-scanning/secret-scanning#get-secret-scanning-scan-history-for-a-repository +// +//meta:operation GET /repos/{owner}/{repo}/secret-scanning/scan-history +func (s *SecretScanningService) ScanHistory(ctx context.Context, owner, repo string) (*SecretScanningResponse, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/secret-scanning/scan-history", owner, repo) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var secretScanningHistory *SecretScanningResponse + resp, err := s.client.Do(ctx, req, &secretScanningHistory) + if err != nil { + return nil, resp, err + } + + return secretScanningHistory, resp, nil +} diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index 779785396f1..f4fde386a29 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -617,3 +617,126 @@ func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } +func TestSecretScanningService_PushProtectionBypasses(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + owner := "o" + repo := "r" + + mux.HandleFunc(fmt.Sprintf("/repos/%v/%v/secret-scanning/push-protection-bypasses", owner, repo), func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + var v *CreatePushProtectionBypass + assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) + want := &CreatePushProtectionBypass{Reason: "valid reason", PlaceholderID: "bypass-123"} + if !cmp.Equal(v, want) { + t.Errorf("Request body = %+v, want %+v", v, want) + } + + fmt.Fprint(w, `{ + "reason": "valid reason", + "expire_at": "2025-07-29T10:00:00Z", + "token_type": "github_token" + }`) + }) + + ctx := context.Background() + opts := &CreatePushProtectionBypass{Reason: "valid reason", PlaceholderID: "bypass-123"} + + bypass, _, err := client.SecretScanning.PushProtectionBypasses(ctx, owner, repo, opts) + if err != nil { + t.Errorf("SecretScanning.PushProtectionBypasses returned error: %v", err) + } + + expireTime, _ := time.Parse(time.RFC3339, "2025-07-29T10:00:00Z") + want := &PushProtectionBypass{ + Reason: "valid reason", + ExpireAt: &expireTime, + TokenType: "github_token", + } + + if !cmp.Equal(bypass, want) { + t.Errorf("SecretScanning.PushProtectionBypasses returned %+v, want %+v", bypass, want) + } + const methodName = "PushProtectionBypasses" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.SecretScanning.PushProtectionBypasses(ctx, "\n", "\n", opts) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + _, resp, err := client.SecretScanning.PushProtectionBypasses(ctx, "o", "r", opts) + return resp, err + }) +} +func TestSecretScanningService_ScanHistory(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + owner := "o" + repo := "r" + + mux.HandleFunc(fmt.Sprintf("/repos/%v/%v/secret-scanning/scan-history", owner, repo), func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "incremental_scans": [ + { + "type": "incremental", + "status": "success", + "completed_at": "2025-07-29T10:00:00Z", + "started_at": "2025-07-29T09:55:00Z" + } + ], + "backfill_scans": [], + "pattern_update_scans": [], + "custom_pattern_backfill_scans": [ + { + "type": "custom_backfill", + "status": "in_progress", + "completed_at": null, + "started_at": "2025-07-29T09:00:00Z", + "pattern_slug": "my-custom-pattern", + "pattern_scope": "organization" + } + ] + }`) + }) + + ctx := context.Background() + + history, _, err := client.SecretScanning.ScanHistory(ctx, owner, repo) + if err != nil { + t.Errorf("SecretScanning.ScanHistory returned error: %v", err) + } + + startAt1, _ := time.Parse(time.RFC3339, "2025-07-29T09:55:00Z") + completeAt1, _ := time.Parse(time.RFC3339, "2025-07-29T10:00:00Z") + startAt2, _ := time.Parse(time.RFC3339, "2025-07-29T09:00:00Z") + + want := &SecretScanningResponse{ + IncrementalScans: []*Scan{ + {Type: "incremental", Status: "success", CompletedAt: &completeAt1, StartedAt: &startAt1}, + }, + BackfillScans: []*Scan{}, + PatternUpdateScans: []*Scan{}, + CustomPatternBackfills: []*CustomPatternScan{ + { + Scan: Scan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: &startAt2}, + PatternSlug: "my-custom-pattern", + PatternScope: "organization", + }, + }, + } + + if !cmp.Equal(history, want) { + t.Errorf("SecretScanning.ScanHistory returned %+v, want %+v", history, want) + } + const methodName = "ScanHistory" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.SecretScanning.ScanHistory(ctx, "\n", "\n") + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + _, resp, err := client.SecretScanning.ScanHistory(ctx, "o", "r") + return resp, err + }) +} From 895f152a1c26c94c71023bf22373be9e82db101b Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 06:05:20 +0530 Subject: [PATCH 02/11] use timestamp instead of time.Time --- github/github-accessors.go | 12 ++++++------ github/github-accessors_test.go | 6 +++--- github/secret_scanning.go | 7 +++---- github/secret_scanning_test.go | 10 +++++----- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 6ce96f908f2..fb08b75fd39 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -20871,9 +20871,9 @@ func (p *PushEventRepository) GetWatchersCount() int { } // GetExpireAt returns the ExpireAt field if it's non-nil, zero value otherwise. -func (p *PushProtectionBypass) GetExpireAt() time.Time { +func (p *PushProtectionBypass) GetExpireAt() Timestamp { if p == nil || p.ExpireAt == nil { - return time.Time{} + return Timestamp{} } return *p.ExpireAt } @@ -24847,17 +24847,17 @@ func (s *SBOMInfo) GetSPDXVersion() string { } // GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. -func (s *Scan) GetCompletedAt() time.Time { +func (s *Scan) GetCompletedAt() Timestamp { if s == nil || s.CompletedAt == nil { - return time.Time{} + return Timestamp{} } return *s.CompletedAt } // GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise. -func (s *Scan) GetStartedAt() time.Time { +func (s *Scan) GetStartedAt() Timestamp { if s == nil || s.StartedAt == nil { - return time.Time{} + return Timestamp{} } return *s.StartedAt } diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 26cec196947..ca947854c64 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -26927,7 +26927,7 @@ func TestPushEventRepository_GetWatchersCount(tt *testing.T) { func TestPushProtectionBypass_GetExpireAt(tt *testing.T) { tt.Parallel() - var zeroValue time.Time + var zeroValue Timestamp p := &PushProtectionBypass{ExpireAt: &zeroValue} p.GetExpireAt() p = &PushProtectionBypass{} @@ -32004,7 +32004,7 @@ func TestSBOMInfo_GetSPDXVersion(tt *testing.T) { func TestScan_GetCompletedAt(tt *testing.T) { tt.Parallel() - var zeroValue time.Time + var zeroValue Timestamp s := &Scan{CompletedAt: &zeroValue} s.GetCompletedAt() s = &Scan{} @@ -32015,7 +32015,7 @@ func TestScan_GetCompletedAt(tt *testing.T) { func TestScan_GetStartedAt(tt *testing.T) { tt.Parallel() - var zeroValue time.Time + var zeroValue Timestamp s := &Scan{StartedAt: &zeroValue} s.GetStartedAt() s = &Scan{} diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 9fe0196790b..8cfe61681dc 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -8,7 +8,6 @@ package github import ( "context" "fmt" - "time" ) // SecretScanningService handles communication with the secret scanning related @@ -130,7 +129,7 @@ type CreatePushProtectionBypass struct { // PushProtectionBypass represents the responses from PushProtectionBypasses. type PushProtectionBypass struct { Reason string `json:"reason"` - ExpireAt *time.Time `json:"expire_at"` + ExpireAt *Timestamp `json:"expire_at"` TokenType string `json:"token_type"` } @@ -138,8 +137,8 @@ type PushProtectionBypass struct { type Scan struct { Type string `json:"type"` Status string `json:"status"` - CompletedAt *time.Time `json:"completed_at"` - StartedAt *time.Time `json:"started_at"` + CompletedAt *Timestamp `json:"completed_at"` + StartedAt *Timestamp `json:"started_at"` } // CustomPatternScan represents a scan with an associated custom pattern. diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index f4fde386a29..4a664cf6ec5 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -635,7 +635,7 @@ func TestSecretScanningService_PushProtectionBypasses(t *testing.T) { fmt.Fprint(w, `{ "reason": "valid reason", - "expire_at": "2025-07-29T10:00:00Z", + "expire_at": "2018-01-01T00:00:00Z", "token_type": "github_token" }`) }) @@ -648,7 +648,7 @@ func TestSecretScanningService_PushProtectionBypasses(t *testing.T) { t.Errorf("SecretScanning.PushProtectionBypasses returned error: %v", err) } - expireTime, _ := time.Parse(time.RFC3339, "2025-07-29T10:00:00Z") + expireTime := Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} want := &PushProtectionBypass{ Reason: "valid reason", ExpireAt: &expireTime, @@ -708,9 +708,9 @@ func TestSecretScanningService_ScanHistory(t *testing.T) { t.Errorf("SecretScanning.ScanHistory returned error: %v", err) } - startAt1, _ := time.Parse(time.RFC3339, "2025-07-29T09:55:00Z") - completeAt1, _ := time.Parse(time.RFC3339, "2025-07-29T10:00:00Z") - startAt2, _ := time.Parse(time.RFC3339, "2025-07-29T09:00:00Z") + startAt1 := Timestamp{time.Date(2025, time.July, 29, 9, 55, 0, 0, time.UTC)} + completeAt1 := Timestamp{time.Date(2025, time.July, 29, 10, 0, 0, 0, time.UTC)} + startAt2 := Timestamp{time.Date(2025, time.July, 29, 9, 0, 0, 0, time.UTC)} want := &SecretScanningResponse{ IncrementalScans: []*Scan{ From 3a24cda807745d650a4ec1d2f31b7e0c382a87a2 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 16:58:11 +0530 Subject: [PATCH 03/11] change method names --- github/secret_scanning.go | 14 +++++++------- github/secret_scanning_test.go | 34 +++++++++++++++++----------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 8cfe61681dc..76be2f95335 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -120,13 +120,13 @@ type SecretScanningAlertUpdateOptions struct { ResolutionComment *string `json:"resolution_comment,omitempty"` } -// CreatePushProtectionBypass represents the parameters for PushProtectionBypasses. -type CreatePushProtectionBypass struct { +// CreatePushProtectionBypass represents the parameters for CreatePushProtectionBypass. +type PushProtectionBypassRequest struct { Reason string `json:"reason"` PlaceholderID string `json:"placeholder_id"` } -// PushProtectionBypass represents the responses from PushProtectionBypasses. +// PushProtectionBypass represents the responses from CreatePushProtectionBypass. type PushProtectionBypass struct { Reason string `json:"reason"` ExpireAt *Timestamp `json:"expire_at"` @@ -322,7 +322,7 @@ func (s *SecretScanningService) ListLocationsForAlert(ctx context.Context, owner return locations, resp, nil } -// PushProtectionBypasses creates a push protection bypass for a given repository. +// CreatePushProtectionBypass creates a push protection bypass for a given repository. // // To use this endpoint, you must be an administrator for the repository or organization, and you must use an access token with // the repo scope or security_events scope. @@ -330,7 +330,7 @@ func (s *SecretScanningService) ListLocationsForAlert(ctx context.Context, owner // GitHub API docs: https://docs.github.com/rest/secret-scanning/secret-scanning#create-a-push-protection-bypass // //meta:operation POST /repos/{owner}/{repo}/secret-scanning/push-protection-bypasses -func (s *SecretScanningService) PushProtectionBypasses(ctx context.Context, owner, repo string, opts *CreatePushProtectionBypass) (*PushProtectionBypass, *Response, error) { +func (s *SecretScanningService) CreatePushProtectionBypass(ctx context.Context, owner, repo string, opts *PushProtectionBypassRequest) (*PushProtectionBypass, *Response, error) { u := fmt.Sprintf("repos/%v/%v/secret-scanning/push-protection-bypasses", owner, repo) req, err := s.client.NewRequest("POST", u, opts) @@ -345,7 +345,7 @@ func (s *SecretScanningService) PushProtectionBypasses(ctx context.Context, owne return reponsePushProtectionBypass, resp, nil } -// ScanHistory fetches the secret scanning history for a given repository. +// GetScanHistory fetches the secret scanning history for a given repository. // // To use this endpoint, you must be an administrator for the repository or organization, and you must use an access token with // the repo scope or security_events scope and gitHub advanced security or secret scanning must be enabled. @@ -353,7 +353,7 @@ func (s *SecretScanningService) PushProtectionBypasses(ctx context.Context, owne // GitHub API docs: https://docs.github.com/rest/secret-scanning/secret-scanning#get-secret-scanning-scan-history-for-a-repository // //meta:operation GET /repos/{owner}/{repo}/secret-scanning/scan-history -func (s *SecretScanningService) ScanHistory(ctx context.Context, owner, repo string) (*SecretScanningResponse, *Response, error) { +func (s *SecretScanningService) GetScanHistory(ctx context.Context, owner, repo string) (*SecretScanningResponse, *Response, error) { u := fmt.Sprintf("repos/%v/%v/secret-scanning/scan-history", owner, repo) req, err := s.client.NewRequest("GET", u, nil) diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index 4a664cf6ec5..c286d3e2ad9 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -617,7 +617,7 @@ func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } -func TestSecretScanningService_PushProtectionBypasses(t *testing.T) { +func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -626,9 +626,9 @@ func TestSecretScanningService_PushProtectionBypasses(t *testing.T) { mux.HandleFunc(fmt.Sprintf("/repos/%v/%v/secret-scanning/push-protection-bypasses", owner, repo), func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - var v *CreatePushProtectionBypass + var v *PushProtectionBypassRequest assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) - want := &CreatePushProtectionBypass{Reason: "valid reason", PlaceholderID: "bypass-123"} + want := &PushProtectionBypassRequest{Reason: "valid reason", PlaceholderID: "bypass-123"} if !cmp.Equal(v, want) { t.Errorf("Request body = %+v, want %+v", v, want) } @@ -641,11 +641,11 @@ func TestSecretScanningService_PushProtectionBypasses(t *testing.T) { }) ctx := context.Background() - opts := &CreatePushProtectionBypass{Reason: "valid reason", PlaceholderID: "bypass-123"} + opts := &PushProtectionBypassRequest{Reason: "valid reason", PlaceholderID: "bypass-123"} - bypass, _, err := client.SecretScanning.PushProtectionBypasses(ctx, owner, repo, opts) + bypass, _, err := client.SecretScanning.CreatePushProtectionBypass(ctx, owner, repo, opts) if err != nil { - t.Errorf("SecretScanning.PushProtectionBypasses returned error: %v", err) + t.Errorf("SecretScanning.CreatePushProtectionBypass returned error: %v", err) } expireTime := Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} @@ -656,19 +656,19 @@ func TestSecretScanningService_PushProtectionBypasses(t *testing.T) { } if !cmp.Equal(bypass, want) { - t.Errorf("SecretScanning.PushProtectionBypasses returned %+v, want %+v", bypass, want) + t.Errorf("SecretScanning.CreatePushProtectionBypass returned %+v, want %+v", bypass, want) } - const methodName = "PushProtectionBypasses" + const methodName = "CreatePushProtectionBypass" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.SecretScanning.PushProtectionBypasses(ctx, "\n", "\n", opts) + _, _, err = client.SecretScanning.CreatePushProtectionBypass(ctx, "\n", "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - _, resp, err := client.SecretScanning.PushProtectionBypasses(ctx, "o", "r", opts) + _, resp, err := client.SecretScanning.CreatePushProtectionBypass(ctx, "o", "r", opts) return resp, err }) } -func TestSecretScanningService_ScanHistory(t *testing.T) { +func TestSecretScanningService_GetScanHistory(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -703,9 +703,9 @@ func TestSecretScanningService_ScanHistory(t *testing.T) { ctx := context.Background() - history, _, err := client.SecretScanning.ScanHistory(ctx, owner, repo) + history, _, err := client.SecretScanning.GetScanHistory(ctx, owner, repo) if err != nil { - t.Errorf("SecretScanning.ScanHistory returned error: %v", err) + t.Errorf("SecretScanning.GetScanHistory returned error: %v", err) } startAt1 := Timestamp{time.Date(2025, time.July, 29, 9, 55, 0, 0, time.UTC)} @@ -728,15 +728,15 @@ func TestSecretScanningService_ScanHistory(t *testing.T) { } if !cmp.Equal(history, want) { - t.Errorf("SecretScanning.ScanHistory returned %+v, want %+v", history, want) + t.Errorf("SecretScanning.GetScanHistory returned %+v, want %+v", history, want) } - const methodName = "ScanHistory" + const methodName = "GetScanHistory" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.SecretScanning.ScanHistory(ctx, "\n", "\n") + _, _, err = client.SecretScanning.GetScanHistory(ctx, "\n", "\n") return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - _, resp, err := client.SecretScanning.ScanHistory(ctx, "o", "r") + _, resp, err := client.SecretScanning.GetScanHistory(ctx, "o", "r") return resp, err }) } From 52ce83a2db576e4518da1e942133c5dc976768b3 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 17:01:55 +0530 Subject: [PATCH 04/11] fix comments --- github/secret_scanning.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 76be2f95335..a3b7bdaa14f 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -120,7 +120,7 @@ type SecretScanningAlertUpdateOptions struct { ResolutionComment *string `json:"resolution_comment,omitempty"` } -// CreatePushProtectionBypass represents the parameters for CreatePushProtectionBypass. +// PushProtectionBypassRequest represents the parameters for CreatePushProtectionBypass. type PushProtectionBypassRequest struct { Reason string `json:"reason"` PlaceholderID string `json:"placeholder_id"` From 9908a2d7834380ed9fd9cd7a5e848122764ffee6 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 18:40:09 +0530 Subject: [PATCH 05/11] add comments to struct and change some name --- github/secret_scanning.go | 38 +++++++++++++++++++++------------- github/secret_scanning_test.go | 4 ++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/github/secret_scanning.go b/github/secret_scanning.go index a3b7bdaa14f..73231b5e114 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -122,15 +122,21 @@ type SecretScanningAlertUpdateOptions struct { // PushProtectionBypassRequest represents the parameters for CreatePushProtectionBypass. type PushProtectionBypassRequest struct { - Reason string `json:"reason"` + // Reason provides a justification for the push protection bypass. + Reason string `json:"reason"` + // PlaceholderID is an identifier used for the bypass request. + // GitHub Secret Scanning provides you with a unique PlaceholderID associated with that specific blocked push. PlaceholderID string `json:"placeholder_id"` } -// PushProtectionBypass represents the responses from CreatePushProtectionBypass. +// PushProtectionBypass represents the response from CreatePushProtectionBypass. type PushProtectionBypass struct { - Reason string `json:"reason"` - ExpireAt *Timestamp `json:"expire_at"` - TokenType string `json:"token_type"` + //The reason for bypassing push protection. + Reason string `json:"reason"` + //The time that the bypass will expire in ISO 8601 format. + ExpireAt *Timestamp `json:"expire_at"` + //The token type this bypass is for. + TokenType string `json:"token_type"` } // Scan represents the common fields for a secret scanning scan. @@ -148,11 +154,15 @@ type CustomPatternScan struct { PatternScope string `json:"pattern_scope,omitempty"` } -// SecretScanningResponse is the top-level struct for the secret scanning API response. -type SecretScanningResponse struct { - IncrementalScans []*Scan `json:"incremental_scans"` - BackfillScans []*Scan `json:"backfill_scans"` - PatternUpdateScans []*Scan `json:"pattern_update_scans"` +// SecretScanningHistory is the top-level struct for the secret scanning API response. +type SecretScanningHistory struct { + //Information on incremental scan performed by secret scanning on the repository. + IncrementalScans []*Scan `json:"incremental_scans"` + //Information on backfill scan performed by secret scanning on the repository. + BackfillScans []*Scan `json:"backfill_scans"` + //Information on pattern update scan performed by secret scanning on the repository. + PatternUpdateScans []*Scan `json:"pattern_update_scans"` + //Information on custom pattern backfill scan performed by secret scanning on the repository. CustomPatternBackfills []*CustomPatternScan `json:"custom_pattern_backfill_scans"` } @@ -330,10 +340,10 @@ func (s *SecretScanningService) ListLocationsForAlert(ctx context.Context, owner // GitHub API docs: https://docs.github.com/rest/secret-scanning/secret-scanning#create-a-push-protection-bypass // //meta:operation POST /repos/{owner}/{repo}/secret-scanning/push-protection-bypasses -func (s *SecretScanningService) CreatePushProtectionBypass(ctx context.Context, owner, repo string, opts *PushProtectionBypassRequest) (*PushProtectionBypass, *Response, error) { +func (s *SecretScanningService) CreatePushProtectionBypass(ctx context.Context, owner, repo string, request PushProtectionBypassRequest) (*PushProtectionBypass, *Response, error) { u := fmt.Sprintf("repos/%v/%v/secret-scanning/push-protection-bypasses", owner, repo) - req, err := s.client.NewRequest("POST", u, opts) + req, err := s.client.NewRequest("POST", u, request) if err != nil { return nil, nil, err } @@ -353,7 +363,7 @@ func (s *SecretScanningService) CreatePushProtectionBypass(ctx context.Context, // GitHub API docs: https://docs.github.com/rest/secret-scanning/secret-scanning#get-secret-scanning-scan-history-for-a-repository // //meta:operation GET /repos/{owner}/{repo}/secret-scanning/scan-history -func (s *SecretScanningService) GetScanHistory(ctx context.Context, owner, repo string) (*SecretScanningResponse, *Response, error) { +func (s *SecretScanningService) GetScanHistory(ctx context.Context, owner, repo string) (*SecretScanningHistory, *Response, error) { u := fmt.Sprintf("repos/%v/%v/secret-scanning/scan-history", owner, repo) req, err := s.client.NewRequest("GET", u, nil) @@ -361,7 +371,7 @@ func (s *SecretScanningService) GetScanHistory(ctx context.Context, owner, repo return nil, nil, err } - var secretScanningHistory *SecretScanningResponse + var secretScanningHistory *SecretScanningHistory resp, err := s.client.Do(ctx, req, &secretScanningHistory) if err != nil { return nil, resp, err diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index c286d3e2ad9..34fadd0c689 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -641,7 +641,7 @@ func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) { }) ctx := context.Background() - opts := &PushProtectionBypassRequest{Reason: "valid reason", PlaceholderID: "bypass-123"} + opts := PushProtectionBypassRequest{Reason: "valid reason", PlaceholderID: "bypass-123"} bypass, _, err := client.SecretScanning.CreatePushProtectionBypass(ctx, owner, repo, opts) if err != nil { @@ -712,7 +712,7 @@ func TestSecretScanningService_GetScanHistory(t *testing.T) { completeAt1 := Timestamp{time.Date(2025, time.July, 29, 10, 0, 0, 0, time.UTC)} startAt2 := Timestamp{time.Date(2025, time.July, 29, 9, 0, 0, 0, time.UTC)} - want := &SecretScanningResponse{ + want := &SecretScanningHistory{ IncrementalScans: []*Scan{ {Type: "incremental", Status: "success", CompletedAt: &completeAt1, StartedAt: &startAt1}, }, From 25437f387674b8994593e7c97a6a8fd467e82db9 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 18:43:37 +0530 Subject: [PATCH 06/11] fix comments --- github/secret_scanning.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 73231b5e114..6be4dc2b0e6 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -131,11 +131,11 @@ type PushProtectionBypassRequest struct { // PushProtectionBypass represents the response from CreatePushProtectionBypass. type PushProtectionBypass struct { - //The reason for bypassing push protection. + // The reason for bypassing push protection. Reason string `json:"reason"` - //The time that the bypass will expire in ISO 8601 format. + // The time that the bypass will expire in ISO 8601 format. ExpireAt *Timestamp `json:"expire_at"` - //The token type this bypass is for. + // The token type this bypass is for. TokenType string `json:"token_type"` } From 317ee25eaff8f342a7a853dd56b9ece255df69ca Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 18:46:24 +0530 Subject: [PATCH 07/11] fix comments --- github/secret_scanning.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 6be4dc2b0e6..6b25038f3ee 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -156,13 +156,13 @@ type CustomPatternScan struct { // SecretScanningHistory is the top-level struct for the secret scanning API response. type SecretScanningHistory struct { - //Information on incremental scan performed by secret scanning on the repository. + // Information on incremental scan performed by secret scanning on the repository. IncrementalScans []*Scan `json:"incremental_scans"` - //Information on backfill scan performed by secret scanning on the repository. + // Information on backfill scan performed by secret scanning on the repository. BackfillScans []*Scan `json:"backfill_scans"` - //Information on pattern update scan performed by secret scanning on the repository. + // Information on pattern update scan performed by secret scanning on the repository. PatternUpdateScans []*Scan `json:"pattern_update_scans"` - //Information on custom pattern backfill scan performed by secret scanning on the repository. + // Information on custom pattern backfill scan performed by secret scanning on the repository. CustomPatternBackfills []*CustomPatternScan `json:"custom_pattern_backfill_scans"` } From 6f7860ed1fb5b1f4f992a3bdaad179e428b76b74 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 19:23:28 +0530 Subject: [PATCH 08/11] add omitempty --- github/secret_scanning.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 6b25038f3ee..7e5e4012517 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -143,8 +143,8 @@ type PushProtectionBypass struct { type Scan struct { Type string `json:"type"` Status string `json:"status"` - CompletedAt *Timestamp `json:"completed_at"` - StartedAt *Timestamp `json:"started_at"` + CompletedAt *Timestamp `json:"completed_at,omitempty"` + StartedAt *Timestamp `json:"started_at,omitempty"` } // CustomPatternScan represents a scan with an associated custom pattern. From c7213dc4e3171e6aebb0d5ecee0252be3ddcb2bc Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 20:06:44 +0530 Subject: [PATCH 09/11] use omitempty where needed and adjust names --- github/github-accessors.go | 48 ++++++++++++++++-------- github/github-accessors_test.go | 66 ++++++++++++++++++++++----------- github/secret_scanning.go | 18 ++++----- github/secret_scanning_test.go | 16 ++++---- 4 files changed, 94 insertions(+), 54 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 47affc98e5e..1b767711bbd 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6558,6 +6558,22 @@ func (c *CustomOrgRoles) GetUpdatedAt() Timestamp { return *c.UpdatedAt } +// GetPatternScope returns the PatternScope field if it's non-nil, zero value otherwise. +func (c *CustomPatternScan) GetPatternScope() string { + if c == nil || c.PatternScope == nil { + return "" + } + return *c.PatternScope +} + +// GetPatternSlug returns the PatternSlug field if it's non-nil, zero value otherwise. +func (c *CustomPatternScan) GetPatternSlug() string { + if c == nil || c.PatternSlug == nil { + return "" + } + return *c.PatternSlug +} + // GetDefaultValue returns the DefaultValue field if it's non-nil, zero value otherwise. func (c *CustomProperty) GetDefaultValue() string { if c == nil || c.DefaultValue == nil { @@ -25038,22 +25054,6 @@ func (s *SBOMInfo) GetSPDXVersion() string { return *s.SPDXVersion } -// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. -func (s *Scan) GetCompletedAt() Timestamp { - if s == nil || s.CompletedAt == nil { - return Timestamp{} - } - return *s.CompletedAt -} - -// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise. -func (s *Scan) GetStartedAt() Timestamp { - if s == nil || s.StartedAt == nil { - return Timestamp{} - } - return *s.StartedAt -} - // GetAnalysisKey returns the AnalysisKey field if it's non-nil, zero value otherwise. func (s *ScanningAnalysis) GetAnalysisKey() string { if s == nil || s.AnalysisKey == nil { @@ -25958,6 +25958,22 @@ func (s *SecretScanningValidityChecks) GetStatus() string { return *s.Status } +// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. +func (s *SecretsScan) GetCompletedAt() Timestamp { + if s == nil || s.CompletedAt == nil { + return Timestamp{} + } + return *s.CompletedAt +} + +// GetStartedAt returns the StartedAt field if it's non-nil, zero value otherwise. +func (s *SecretsScan) GetStartedAt() Timestamp { + if s == nil || s.StartedAt == nil { + return Timestamp{} + } + return *s.StartedAt +} + // GetAuthor returns the Author field. func (s *SecurityAdvisory) GetAuthor() *User { if s == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 6fd0fc0b4e9..6c7d492783d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -8566,6 +8566,28 @@ func TestCustomOrgRoles_GetUpdatedAt(tt *testing.T) { c.GetUpdatedAt() } +func TestCustomPatternScan_GetPatternScope(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CustomPatternScan{PatternScope: &zeroValue} + c.GetPatternScope() + c = &CustomPatternScan{} + c.GetPatternScope() + c = nil + c.GetPatternScope() +} + +func TestCustomPatternScan_GetPatternSlug(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CustomPatternScan{PatternSlug: &zeroValue} + c.GetPatternSlug() + c = &CustomPatternScan{} + c.GetPatternSlug() + c = nil + c.GetPatternSlug() +} + func TestCustomProperty_GetDefaultValue(tt *testing.T) { tt.Parallel() var zeroValue string @@ -32257,28 +32279,6 @@ func TestSBOMInfo_GetSPDXVersion(tt *testing.T) { s.GetSPDXVersion() } -func TestScan_GetCompletedAt(tt *testing.T) { - tt.Parallel() - var zeroValue Timestamp - s := &Scan{CompletedAt: &zeroValue} - s.GetCompletedAt() - s = &Scan{} - s.GetCompletedAt() - s = nil - s.GetCompletedAt() -} - -func TestScan_GetStartedAt(tt *testing.T) { - tt.Parallel() - var zeroValue Timestamp - s := &Scan{StartedAt: &zeroValue} - s.GetStartedAt() - s = &Scan{} - s.GetStartedAt() - s = nil - s.GetStartedAt() -} - func TestScanningAnalysis_GetAnalysisKey(tt *testing.T) { tt.Parallel() var zeroValue string @@ -33459,6 +33459,28 @@ func TestSecretScanningValidityChecks_GetStatus(tt *testing.T) { s.GetStatus() } +func TestSecretsScan_GetCompletedAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + s := &SecretsScan{CompletedAt: &zeroValue} + s.GetCompletedAt() + s = &SecretsScan{} + s.GetCompletedAt() + s = nil + s.GetCompletedAt() +} + +func TestSecretsScan_GetStartedAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + s := &SecretsScan{StartedAt: &zeroValue} + s.GetStartedAt() + s = &SecretsScan{} + s.GetStartedAt() + s = nil + s.GetStartedAt() +} + func TestSecurityAdvisory_GetAuthor(tt *testing.T) { tt.Parallel() s := &SecurityAdvisory{} diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 7e5e4012517..b9431ccd354 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -139,8 +139,8 @@ type PushProtectionBypass struct { TokenType string `json:"token_type"` } -// Scan represents the common fields for a secret scanning scan. -type Scan struct { +// SecretsScan represents the common fields for a secret scanning scan. +type SecretsScan struct { Type string `json:"type"` Status string `json:"status"` CompletedAt *Timestamp `json:"completed_at,omitempty"` @@ -149,21 +149,21 @@ type Scan struct { // CustomPatternScan represents a scan with an associated custom pattern. type CustomPatternScan struct { - Scan - PatternSlug string `json:"pattern_slug,omitempty"` - PatternScope string `json:"pattern_scope,omitempty"` + SecretsScan + PatternSlug *string `json:"pattern_slug,omitempty"` + PatternScope *string `json:"pattern_scope,omitempty"` } // SecretScanningHistory is the top-level struct for the secret scanning API response. type SecretScanningHistory struct { // Information on incremental scan performed by secret scanning on the repository. - IncrementalScans []*Scan `json:"incremental_scans"` + IncrementalScans []*SecretsScan `json:"incremental_scans,omitempty"` // Information on backfill scan performed by secret scanning on the repository. - BackfillScans []*Scan `json:"backfill_scans"` + BackfillScans []*SecretsScan `json:"backfill_scans,omitempty"` // Information on pattern update scan performed by secret scanning on the repository. - PatternUpdateScans []*Scan `json:"pattern_update_scans"` + PatternUpdateScans []*SecretsScan `json:"pattern_update_scans,omitempty"` // Information on custom pattern backfill scan performed by secret scanning on the repository. - CustomPatternBackfills []*CustomPatternScan `json:"custom_pattern_backfill_scans"` + CustomPatternBackfillScans []*CustomPatternScan `json:"custom_pattern_backfill_scans,omitempty"` } // ListAlertsForEnterprise lists secret scanning alerts for eligible repositories in an enterprise, from newest to oldest. diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index 34fadd0c689..c0929776847 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -617,6 +617,7 @@ func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } + func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -668,6 +669,7 @@ func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) { return resp, err }) } + func TestSecretScanningService_GetScanHistory(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -713,16 +715,16 @@ func TestSecretScanningService_GetScanHistory(t *testing.T) { startAt2 := Timestamp{time.Date(2025, time.July, 29, 9, 0, 0, 0, time.UTC)} want := &SecretScanningHistory{ - IncrementalScans: []*Scan{ + IncrementalScans: []*SecretsScan{ {Type: "incremental", Status: "success", CompletedAt: &completeAt1, StartedAt: &startAt1}, }, - BackfillScans: []*Scan{}, - PatternUpdateScans: []*Scan{}, - CustomPatternBackfills: []*CustomPatternScan{ + BackfillScans: []*SecretsScan{}, + PatternUpdateScans: []*SecretsScan{}, + CustomPatternBackfillScans: []*CustomPatternScan{ { - Scan: Scan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: &startAt2}, - PatternSlug: "my-custom-pattern", - PatternScope: "organization", + SecretsScan: SecretsScan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: &startAt2}, + PatternSlug: Ptr("my-custom-pattern"), + PatternScope: Ptr("organization"), }, }, } From 1d091ff11a3c0974ec67e8778cd1ecb640d9a6b2 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Mon, 18 Aug 2025 22:06:27 +0530 Subject: [PATCH 10/11] fix responsePushProtectionBypass --- github/secret_scanning.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/secret_scanning.go b/github/secret_scanning.go index b9431ccd354..413d150751c 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -347,12 +347,12 @@ func (s *SecretScanningService) CreatePushProtectionBypass(ctx context.Context, if err != nil { return nil, nil, err } - var reponsePushProtectionBypass *PushProtectionBypass - resp, err := s.client.Do(ctx, req, &reponsePushProtectionBypass) + var responsePushProtectionBypass *PushProtectionBypass + resp, err := s.client.Do(ctx, req, &responsePushProtectionBypass) if err != nil { return nil, resp, err } - return reponsePushProtectionBypass, resp, nil + return responsePushProtectionBypass, resp, nil } // GetScanHistory fetches the secret scanning history for a given repository. From d92b8d29dfa789630d582ef1ad121611150efff1 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Tue, 30 Sep 2025 17:17:15 +0530 Subject: [PATCH 11/11] change struct name --- github/github-accessors.go | 4 ++-- github/github-accessors_test.go | 12 ++++++------ github/secret_scanning.go | 24 +++++++++++++----------- github/secret_scanning_test.go | 14 +++++++------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index af55ff9bdab..cffb25bb97c 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6559,7 +6559,7 @@ func (c *CustomOrgRoles) GetUpdatedAt() Timestamp { } // GetPatternScope returns the PatternScope field if it's non-nil, zero value otherwise. -func (c *CustomPatternScan) GetPatternScope() string { +func (c *CustomPatternBackfillScan) GetPatternScope() string { if c == nil || c.PatternScope == nil { return "" } @@ -6567,7 +6567,7 @@ func (c *CustomPatternScan) GetPatternScope() string { } // GetPatternSlug returns the PatternSlug field if it's non-nil, zero value otherwise. -func (c *CustomPatternScan) GetPatternSlug() string { +func (c *CustomPatternBackfillScan) GetPatternSlug() string { if c == nil || c.PatternSlug == nil { return "" } diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 2764f67ce20..3bc8491c358 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -8566,23 +8566,23 @@ func TestCustomOrgRoles_GetUpdatedAt(tt *testing.T) { c.GetUpdatedAt() } -func TestCustomPatternScan_GetPatternScope(tt *testing.T) { +func TestCustomPatternBackfillScan_GetPatternScope(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CustomPatternScan{PatternScope: &zeroValue} + c := &CustomPatternBackfillScan{PatternScope: &zeroValue} c.GetPatternScope() - c = &CustomPatternScan{} + c = &CustomPatternBackfillScan{} c.GetPatternScope() c = nil c.GetPatternScope() } -func TestCustomPatternScan_GetPatternSlug(tt *testing.T) { +func TestCustomPatternBackfillScan_GetPatternSlug(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CustomPatternScan{PatternSlug: &zeroValue} + c := &CustomPatternBackfillScan{PatternSlug: &zeroValue} c.GetPatternSlug() - c = &CustomPatternScan{} + c = &CustomPatternBackfillScan{} c.GetPatternSlug() c = nil c.GetPatternSlug() diff --git a/github/secret_scanning.go b/github/secret_scanning.go index 413d150751c..2cedb5a4c80 100644 --- a/github/secret_scanning.go +++ b/github/secret_scanning.go @@ -122,7 +122,8 @@ type SecretScanningAlertUpdateOptions struct { // PushProtectionBypassRequest represents the parameters for CreatePushProtectionBypass. type PushProtectionBypassRequest struct { - // Reason provides a justification for the push protection bypass. + // The reason for bypassing push protection. + // Can be one of: false_positive, used_in_tests, will_fix_later Reason string `json:"reason"` // PlaceholderID is an identifier used for the bypass request. // GitHub Secret Scanning provides you with a unique PlaceholderID associated with that specific blocked push. @@ -147,15 +148,15 @@ type SecretsScan struct { StartedAt *Timestamp `json:"started_at,omitempty"` } -// CustomPatternScan represents a scan with an associated custom pattern. -type CustomPatternScan struct { +// CustomPatternBackfillScan represents a scan with an associated custom pattern. +type CustomPatternBackfillScan struct { SecretsScan PatternSlug *string `json:"pattern_slug,omitempty"` PatternScope *string `json:"pattern_scope,omitempty"` } -// SecretScanningHistory is the top-level struct for the secret scanning API response. -type SecretScanningHistory struct { +// SecretScanningScanHistory is the top-level struct for the secret scanning API response. +type SecretScanningScanHistory struct { // Information on incremental scan performed by secret scanning on the repository. IncrementalScans []*SecretsScan `json:"incremental_scans,omitempty"` // Information on backfill scan performed by secret scanning on the repository. @@ -163,7 +164,7 @@ type SecretScanningHistory struct { // Information on pattern update scan performed by secret scanning on the repository. PatternUpdateScans []*SecretsScan `json:"pattern_update_scans,omitempty"` // Information on custom pattern backfill scan performed by secret scanning on the repository. - CustomPatternBackfillScans []*CustomPatternScan `json:"custom_pattern_backfill_scans,omitempty"` + CustomPatternBackfillScans []*CustomPatternBackfillScan `json:"custom_pattern_backfill_scans,omitempty"` } // ListAlertsForEnterprise lists secret scanning alerts for eligible repositories in an enterprise, from newest to oldest. @@ -347,12 +348,13 @@ func (s *SecretScanningService) CreatePushProtectionBypass(ctx context.Context, if err != nil { return nil, nil, err } - var responsePushProtectionBypass *PushProtectionBypass - resp, err := s.client.Do(ctx, req, &responsePushProtectionBypass) + + var pushProtectionBypass *PushProtectionBypass + resp, err := s.client.Do(ctx, req, &pushProtectionBypass) if err != nil { return nil, resp, err } - return responsePushProtectionBypass, resp, nil + return pushProtectionBypass, resp, nil } // GetScanHistory fetches the secret scanning history for a given repository. @@ -363,7 +365,7 @@ func (s *SecretScanningService) CreatePushProtectionBypass(ctx context.Context, // GitHub API docs: https://docs.github.com/rest/secret-scanning/secret-scanning#get-secret-scanning-scan-history-for-a-repository // //meta:operation GET /repos/{owner}/{repo}/secret-scanning/scan-history -func (s *SecretScanningService) GetScanHistory(ctx context.Context, owner, repo string) (*SecretScanningHistory, *Response, error) { +func (s *SecretScanningService) GetScanHistory(ctx context.Context, owner, repo string) (*SecretScanningScanHistory, *Response, error) { u := fmt.Sprintf("repos/%v/%v/secret-scanning/scan-history", owner, repo) req, err := s.client.NewRequest("GET", u, nil) @@ -371,7 +373,7 @@ func (s *SecretScanningService) GetScanHistory(ctx context.Context, owner, repo return nil, nil, err } - var secretScanningHistory *SecretScanningHistory + var secretScanningHistory *SecretScanningScanHistory resp, err := s.client.Do(ctx, req, &secretScanningHistory) if err != nil { return nil, resp, err diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index c878d51d691..08507442376 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -710,19 +710,19 @@ func TestSecretScanningService_GetScanHistory(t *testing.T) { t.Errorf("SecretScanning.GetScanHistory returned error: %v", err) } - startAt1 := Timestamp{time.Date(2025, time.July, 29, 9, 55, 0, 0, time.UTC)} - completeAt1 := Timestamp{time.Date(2025, time.July, 29, 10, 0, 0, 0, time.UTC)} - startAt2 := Timestamp{time.Date(2025, time.July, 29, 9, 0, 0, 0, time.UTC)} + incrementalScanStartAt := Timestamp{time.Date(2025, time.July, 29, 9, 55, 0, 0, time.UTC)} + incrementalScancompleteAt := Timestamp{time.Date(2025, time.July, 29, 10, 0, 0, 0, time.UTC)} + customPatternBackfillScanStartedAt := Timestamp{time.Date(2025, time.July, 29, 9, 0, 0, 0, time.UTC)} - want := &SecretScanningHistory{ + want := &SecretScanningScanHistory{ IncrementalScans: []*SecretsScan{ - {Type: "incremental", Status: "success", CompletedAt: &completeAt1, StartedAt: &startAt1}, + {Type: "incremental", Status: "success", CompletedAt: &incrementalScancompleteAt, StartedAt: &incrementalScanStartAt}, }, BackfillScans: []*SecretsScan{}, PatternUpdateScans: []*SecretsScan{}, - CustomPatternBackfillScans: []*CustomPatternScan{ + CustomPatternBackfillScans: []*CustomPatternBackfillScan{ { - SecretsScan: SecretsScan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: &startAt2}, + SecretsScan: SecretsScan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: &customPatternBackfillScanStartedAt}, PatternSlug: Ptr("my-custom-pattern"), PatternScope: Ptr("organization"), },