Skip to content

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

Open
tanayarun wants to merge 3 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 3 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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.53%. Comparing base (ed10621) to head (bae53cf).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4397   +/-   ##
=======================================
  Coverage   97.52%   97.53%           
=======================================
  Files         193      194    +1     
  Lines       19668    19704   +36     
=======================================
+ Hits        19182    19218   +36     
  Misses        269      269           
  Partials      217      217           

☔ 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.

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.

3 participants