UploadSarif uploads the result of code scanning job to GitHub. For the parameter sarif, you must first compress your SARIF file using gzip and then translate the contents of the file into a Base64 encoding string. You must use an access token with the security_events scope to use this endpoint. Git
(ctx context.Context, owner, repo string, sarif *SarifAnalysis)
| 393 | // |
| 394 | //meta:operation POST /repos/{owner}/{repo}/code-scanning/sarifs |
| 395 | func (s *CodeScanningService) UploadSarif(ctx context.Context, owner, repo string, sarif *SarifAnalysis) (*SarifID, *Response, error) { |
| 396 | u := fmt.Sprintf("repos/%v/%v/code-scanning/sarifs", owner, repo) |
| 397 | |
| 398 | req, err := s.client.NewRequest(ctx, "POST", u, sarif) |
| 399 | if err != nil { |
| 400 | return nil, nil, err |
| 401 | } |
| 402 | |
| 403 | // This will always return an error without unmarshaling the data |
| 404 | resp, err := s.client.Do(req, nil) |
| 405 | // Even though there was an error, we still return the response |
| 406 | // in case the caller wants to inspect it further. |
| 407 | // However, if the error is AcceptedError, decode it below before |
| 408 | // returning from this function and closing the response body. |
| 409 | var acceptedError *AcceptedError |
| 410 | if !errors.As(err, &acceptedError) { |
| 411 | return nil, resp, err |
| 412 | } |
| 413 | var sarifID *SarifID |
| 414 | decErr := json.Unmarshal(acceptedError.Raw, &sarifID) |
| 415 | if decErr != nil { |
| 416 | return nil, resp, decErr |
| 417 | } |
| 418 | |
| 419 | return sarifID, resp, nil |
| 420 | } |
| 421 | |
| 422 | // SARIFUpload represents information about a SARIF upload. |
| 423 | type SARIFUpload struct { |