Skip to content

Commit 8d7ad2d

Browse files
refactor!: Pass SarifAnalysis by value (#4394)
BREAKING CHANGE: `CodeScanningService.UploadSarif` now takes `body` by value and its required fields are no longer pointers.
1 parent bf1261b commit 8d7ad2d

5 files changed

Lines changed: 37 additions & 27 deletions

File tree

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ linters:
259259
- RequiredStatusChecksRequest
260260
- ReviewCustomDeploymentProtectionRuleRequest
261261
- SCIMUserAttributes
262-
- SarifAnalysis
263262
- SecretScanningAlertUpdateOptions
264263
- SecretScanningPatternConfigsUpdateOptions
265264
- SourceImportAuthor

github/code_scanning.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ type ScanningAnalysis struct {
209209
//
210210
// GitHub API docs: https://docs.github.com/rest/code-scanning?apiVersion=2022-11-28
211211
type SarifAnalysis struct {
212-
CommitSHA *string `json:"commit_sha,omitempty"`
213-
Ref *string `json:"ref,omitempty"`
214-
Sarif *string `json:"sarif,omitempty"`
212+
CommitSHA string `json:"commit_sha"`
213+
Ref string `json:"ref"`
214+
Sarif string `json:"sarif"`
215215
CheckoutURI *string `json:"checkout_uri,omitempty"`
216216
StartedAt *Timestamp `json:"started_at,omitempty"`
217217
ToolName *string `json:"tool_name,omitempty"`
218+
Validate *bool `json:"validate,omitempty"`
218219
}
219220

220221
// CodeScanningAlertState specifies the state of a code scanning alert.
@@ -392,7 +393,7 @@ func (s *CodeScanningService) ListAlertInstances(ctx context.Context, owner, rep
392393
// GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning?apiVersion=2022-11-28#upload-an-analysis-as-sarif-data
393394
//
394395
//meta:operation POST /repos/{owner}/{repo}/code-scanning/sarifs
395-
func (s *CodeScanningService) UploadSarif(ctx context.Context, owner, repo string, body *SarifAnalysis) (*SarifID, *Response, error) {
396+
func (s *CodeScanningService) UploadSarif(ctx context.Context, owner, repo string, body SarifAnalysis) (*SarifID, *Response, error) {
396397
u := fmt.Sprintf("repos/%v/%v/code-scanning/sarifs", owner, repo)
397398

398399
req, err := s.client.NewRequest(ctx, "POST", u, body)

github/code_scanning_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestCodeScanningService_UploadSarif(t *testing.T) {
6262
URL: Ptr("https://example.com/testurl"),
6363
}
6464

65-
sarifAnalysis := &SarifAnalysis{CommitSHA: Ptr("abc"), Ref: Ptr("ref/head/main"), Sarif: Ptr("abc"), CheckoutURI: Ptr("uri"), StartedAt: &referenceTimestamp, ToolName: Ptr("codeql-cli")}
65+
sarifAnalysis := SarifAnalysis{CommitSHA: "abc", Ref: "ref/head/main", Sarif: "abc", CheckoutURI: Ptr("uri"), StartedAt: &referenceTimestamp, ToolName: Ptr("codeql-cli"), Validate: Ptr(true)}
6666

6767
mux.HandleFunc("/repos/o/r/code-scanning/sarifs", func(w http.ResponseWriter, r *http.Request) {
6868
testMethod(t, r, "POST")

github/github-accessors.go

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)