-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add CodeScanningService.ListAnalysesForRepo and CodeScanningService.GetAnalysis #2210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
c0987ad
94bbbe0
7c83191
4421a38
94d6ae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,38 @@ type AlertListOptions struct { | |
| ListOptions | ||
| } | ||
|
|
||
| // AnalysesListOptions specifies optional parameters to the CodeScanningService.ListAnalysesForRepo method. | ||
| type AnalysesListOptions struct { | ||
| // Return code scanning analyses belonging to the same SARIF upload. | ||
| SarifID string `url:"sarif_id,omitempty"` | ||
|
|
||
| // Return code scanning analyses for a specific branch reference. The ref can be formatted as refs/heads/<branch name> or simply <branch name>. | ||
| Ref string `url:"ref,omitempty"` | ||
yogur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ListOptions | ||
| } | ||
|
|
||
| // Analysis represents an individual GitHub Code Scanning Analysis on a single repository. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-analyses-for-a-repository | ||
| type Analysis struct { | ||
|
||
| ID *int64 `json:"id,omitempty"` | ||
| Ref *string `json:"ref,omitempty"` | ||
| CommitSha *string `json:"commit_sha,omitempty"` | ||
yogur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| AnalysisKey *string `json:"analysis_key,omitempty"` | ||
| Environment *string `json:"environment,omitempty"` | ||
| Error *string `json:"error,omitempty"` | ||
| Category *string `json:"category,omitempty"` | ||
| CreatedAt *Timestamp `json:"created_at,omitempty"` | ||
| ResultsCount *int `json:"results_count,omitempty"` | ||
| RulesCount *int `json:"rules_count,omitempty"` | ||
| URL *string `json:"url,omitempty"` | ||
| SarifID *string `json:"sarif_id,omitempty"` | ||
| Tool *Tool `json:"tool,omitempty"` | ||
| Deletable *bool `json:"deletable,omitempty"` | ||
| Warning *string `json:"warning,omitempty"` | ||
| } | ||
|
|
||
| // SarifAnalysis specifies the results of a code scanning job. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#upload-an-analysis-as-sarif-data | ||
|
|
@@ -215,3 +247,56 @@ func (s *CodeScanningService) UploadSarif(ctx context.Context, owner, repo strin | |
|
|
||
| return sarifID, resp, nil | ||
| } | ||
|
|
||
| // ListAnalysesForRepo lists code scanning analyses for a repository. | ||
| // | ||
| // Lists the details of all code scanning analyses for a repository, starting with the most recent. | ||
| // You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events | ||
| // read permission to use this endpoint. | ||
yogur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-analyses-for-a-repository | ||
| func (s *CodeScanningService) ListAnalysesForRepo(ctx context.Context, owner, repo string, opts *AnalysesListOptions) ([]*Analysis, *Response, error) { | ||
| u := fmt.Sprintf("repos/%v/%v/code-scanning/analyses", owner, repo) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var analyses []*Analysis | ||
| resp, err := s.client.Do(ctx, req, &analyses) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return analyses, resp, nil | ||
| } | ||
|
|
||
| // GetAnalysis gets a single code scanning analysis for a repository. | ||
| // | ||
| // You must use an access token with the security_events scope to use this endpoint. | ||
| // GitHub Apps must have the security_events read permission to use this endpoint. | ||
| // | ||
| // The security analysis_id is the ID of the analysis, as returned from the ListAnalysesForRepo operation. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#get-a-code-scanning-analysis-for-a-repository | ||
| func (s *CodeScanningService) GetAnalysis(ctx context.Context, owner, repo string, id int64) (*Analysis, *Response, error) { | ||
| u := fmt.Sprintf("repos/%v/%v/code-scanning/analyses/%v", owner, repo, id) | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| analysis := new(Analysis) | ||
| resp, err := s.client.Do(ctx, req, analysis) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return analysis, resp, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.