feat: Add repo-level secret scanning custom patterns support#4397
feat: Add repo-level secret scanning custom patterns support#4397tanayarun wants to merge 3 commits into
Conversation
|
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. |
6fd23a3 to
27a3a43
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
…ustom-patterns-repo
| // 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
| 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) { |
There was a problem hiding this comment.
| 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) { |
There was a problem hiding this comment.
| 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) { |
| createdAt, _ := time.Parse(time.RFC3339, "2026-07-01T00:00:00Z") | ||
| updatedAt, _ := time.Parse(time.RFC3339, "2026-07-02T00:00:00Z") |
There was a problem hiding this comment.
It's better to use time.Date instead of time.Parse
There was a problem hiding this comment.
And ideally, use the referenceTime consts/vars here:
https://github.com/google/go-github/blob/master/github/timestamp_test.go#L14-L29
|
Thanks for the review @gmlewis @alexandear, i will make changes according to your suggestions and push. |
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.
SecretScanningCustomPattern,SecretScanningCustomPatternRequest,and related request/response types to
secret_scanning_custom_patterns.goListCustomPatternsForRepo,CreateCustomPatternsForRepo,UpdateCustomPatternForRepo,DeleteCustomPatternsForRepotoSecretScanningServicego generate ./...to update accessors andopenapi_operations.yaml