Skip to content

feat: Add repo-level secret scanning custom patterns support#4397

Open
tanayarun wants to merge 6 commits into
google:masterfrom
tanayarun:secret-scanning-custom-patterns-repo
Open

feat: Add repo-level secret scanning custom patterns support#4397
tanayarun wants to merge 6 commits into
google:masterfrom
tanayarun:secret-scanning-custom-patterns-repo

Conversation

@tanayarun

Copy link
Copy Markdown

Adds support for managing secret scanning custom patterns at the
repository level: list, create, update, and delete.

Related to #4381.

This is one of three planned PRs to fully resolve the issue, per the suggestion to split by scope (repo / org / enterprise)
rather than one large PR.

  • Added SecretScanningCustomPattern, SecretScanningCustomPatternRequest,
    and related request/response types to secret_scanning_custom_patterns.go
  • Added ListCustomPatternsForRepo, CreateCustomPatternsForRepo,
    UpdateCustomPatternForRepo, DeleteCustomPatternsForRepo to
    SecretScanningService
  • Ran go generate ./... to update accessors and openapi_operations.yaml
  • Added table-driven tests covering all four methods

@google-cla

google-cla Bot commented Jul 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@tanayarun
tanayarun force-pushed the secret-scanning-custom-patterns-repo branch from 6fd23a3 to 27a3a43 Compare July 19, 2026 11:26
Comment thread openapi_operations.yaml
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.52%. Comparing base (e5f31b2) to head (e1f9c00).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
github/secret_scanning_custom_patterns.go 94.87% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4397      +/-   ##
==========================================
- Coverage   97.52%   97.52%   -0.01%     
==========================================
  Files         193      194       +1     
  Lines       19668    19724      +56     
==========================================
+ Hits        19182    19236      +54     
- Misses        268      269       +1     
- Partials      218      219       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Jul 19, 2026
// GitHub API docs: https://docs.github.com/rest/secret-scanning/custom-patterns?apiVersion=2022-11-28#list-repository-custom-patterns
//
//meta:operation GET /repos/{owner}/{repo}/secret-scanning/custom-patterns
func (s *SecretScanningService) ListCustomPatternsForRepo(ctx context.Context, owner, repo string) ([]*SecretScanningCustomPattern, *Response, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official docs state that this method supports a number of query parameters that are simply missing here. Please check the docs and add an appropriate opts parameter, similar to other methods in this repo.

Please check the official docs of all the other methods as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @gmlewis,
I have checked the docs (https://docs.github.com/en/rest/secret-scanning/custom-patterns), confirmed List supports state, push_protection, sort, direction, page, per_page as query params. I also checked Create/Update/Delete and they only take body parameters, no query params are listed for those.
Planning to add a SecretScanningCustomPatternListOptions struct (ListOptions for pagination) and pass it as an opts param to ListCustomPatternsForRepo, same as the pattern used elsewhere in secret_scanning.go.
Will push once I hear back from you and if i am correct, lemme know if i am making any mistake.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on my phone right now. Why don't you go ahead and give it your best shot to follow and implement the official documentation. If you are able, try out your implementation on one of your live repos. Then you can move forward with this PR without having to wait for me.

@alexandear alexandear left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add comments to all introduced fields?

// GitHub API docs: https://docs.github.com/rest/secret-scanning/custom-patterns?apiVersion=2022-11-28#bulk-delete-repository-custom-patterns
//
//meta:operation DELETE /repos/{owner}/{repo}/secret-scanning/custom-patterns
func (s *SecretScanningService) DeleteCustomPatternsForRepo(ctx context.Context, owner, repo string, patterns *SecretScanningCustomPatternsDeleteRequest) (*Response, error) {

@alexandear alexandear Jul 20, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (s *SecretScanningService) DeleteCustomPatternsForRepo(ctx context.Context, owner, repo string, patterns *SecretScanningCustomPatternsDeleteRequest) (*Response, error) {
func (s *SecretScanningService) DeleteCustomPatternsForRepo(ctx context.Context, owner, repo string, body SecretScanningDeleteCustomPatternsRequest) (*Response, error) {

// GitHub API docs: https://docs.github.com/rest/secret-scanning/custom-patterns?apiVersion=2022-11-28#bulk-create-repository-custom-patterns
//
//meta:operation POST /repos/{owner}/{repo}/secret-scanning/custom-patterns
func (s *SecretScanningService) CreateCustomPatternsForRepo(ctx context.Context, owner, repo string, body SecretScanningCustomPatternsCreateRequest) (*SecretScanningCustomPatternsCreateResponse, *Response, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (s *SecretScanningService) CreateCustomPatternsForRepo(ctx context.Context, owner, repo string, body SecretScanningCustomPatternsCreateRequest) (*SecretScanningCustomPatternsCreateResponse, *Response, error) {
func (s *SecretScanningService) CreateCustomPatternsForRepo(ctx context.Context, owner, repo string, body SecretScanningCreateCustomPatternsRequest) (*SecretScanningCustomPatternsCreateResponse, *Response, error) {

// GitHub API docs: https://docs.github.com/rest/secret-scanning/custom-patterns?apiVersion=2022-11-28#update-a-repository-custom-pattern
//
//meta:operation PATCH /repos/{owner}/{repo}/secret-scanning/custom-patterns/{pattern_id}
func (s *SecretScanningService) UpdateCustomPatternForRepo(ctx context.Context, owner, repo string, patternID int64, body SecretScanningCustomPatternUpdateRequest) (*SecretScanningCustomPattern, *Response, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (s *SecretScanningService) UpdateCustomPatternForRepo(ctx context.Context, owner, repo string, patternID int64, body SecretScanningCustomPatternUpdateRequest) (*SecretScanningCustomPattern, *Response, error) {
func (s *SecretScanningService) UpdateCustomPatternForRepo(ctx context.Context, owner, repo string, patternID int64, body SecretScanningUpdateCustomPatternRequest) (*SecretScanningCustomPattern, *Response, error) {

Comment on lines +48 to +49
createdAt, _ := time.Parse(time.RFC3339, "2026-07-01T00:00:00Z")
updatedAt, _ := time.Parse(time.RFC3339, "2026-07-02T00:00:00Z")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use time.Date instead of time.Parse

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And ideally, use the referenceTime consts/vars here:
https://github.com/google/go-github/blob/master/github/timestamp_test.go#L14-L29

@tanayarun

Copy link
Copy Markdown
Author

Thanks for the review @gmlewis @alexandear, i will make changes according to your suggestions and push.

@tanayarun

Copy link
Copy Markdown
Author

@gmlewis @alexandear Pushed updates according to all the suggestions:

  • Added opts to ListCustomPatternsForRepo (state, push_protection,
    sort, direction, page, per_page).
    Create/Update/Delete have no query params
  • Renamed request types to Create/Update/Delete prefixed, passed by value
  • Added doc comments to all struct fields
  • Test now uses referenceTimeStr/referenceTimestamp instead of time.Parse

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @tanayarun!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @alexandear - @Not-Dhananjay-Mishra


// State is the publish state of the pattern. Possible values are:
// "published" or "unpublished".
State *string `json:"state,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
State *string `json:"state,omitempty"`
State string `json:"state"`

state is required according to the response schema.

    "required": [
      "id",
      "name",
      "pattern",
      "slug",
      "state",
      "push_protection_enabled"
    ]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Not-Dhananjay-Mishra i have pushed the change along with updated tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants