MCPcopy Index your code
hub / github.com/google/go-github / UploadSarif

Method UploadSarif

github/code_scanning.go:395–420  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

393//
394//meta:operation POST /repos/{owner}/{repo}/code-scanning/sarifs
395func (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.
423type SARIFUpload struct {

Callers 1

Calls 2

NewRequestMethod · 0.80
DoMethod · 0.45

Tested by 1