Skip to content
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

Add new query params for AlertListOptions #2848

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions github/code-scanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ type AlertListOptions struct {
// Return code scanning alerts for a specific branch reference. The ref must be formatted as heads/<branch name>.
Ref string `url:"ref,omitempty"`

// If specified, only code scanning alerts with this severity will be returned. Possible values are: critical, high, medium, low, warning, note, error.
Severity string `url:"severity,omitempty"`

// The name of a code scanning tool. Only results by this tool will be listed.
ToolName string `url:"tool_name,omitempty"`

ListCursorOptions

// Add ListOptions so offset pagination with integer type "page" query parameter is accepted
Expand Down
12 changes: 6 additions & 6 deletions github/code-scanning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) {

mux.HandleFunc("/orgs/o/code-scanning/alerts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"state": "open", "ref": "heads/master"})
testFormValues(t, r, values{"state": "open", "ref": "heads/master", "severity": "warning", "tool_name": "CodeQL"})
fmt.Fprint(w, `[{
"repository": {
"id": 1,
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) {
}]`)
})

opts := &AlertListOptions{State: "open", Ref: "heads/master"}
opts := &AlertListOptions{State: "open", Ref: "heads/master", Severity: "warning", ToolName: "CodeQL"}
ctx := context.Background()
alerts, _, err := client.CodeScanning.ListAlertsForOrg(ctx, "o", opts)
if err != nil {
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) {

mux.HandleFunc("/orgs/o/code-scanning/alerts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"state": "open", "ref": "heads/master", "per_page": "1", "before": "deadbeefb", "after": "deadbeefa"})
testFormValues(t, r, values{"state": "open", "ref": "heads/master", "severity": "warning", "tool_name": "CodeQL", "per_page": "1", "before": "deadbeefb", "after": "deadbeefa"})
fmt.Fprint(w, `[{
"repository": {
"id": 1,
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) {
}]`)
})

opts := &AlertListOptions{State: "open", Ref: "heads/master", ListCursorOptions: ListCursorOptions{PerPage: 1, Before: "deadbeefb", After: "deadbeefa"}}
opts := &AlertListOptions{State: "open", Ref: "heads/master", Severity: "warning", ToolName: "CodeQL", ListCursorOptions: ListCursorOptions{PerPage: 1, Before: "deadbeefb", After: "deadbeefa"}}
ctx := context.Background()
alerts, _, err := client.CodeScanning.ListAlertsForOrg(ctx, "o", opts)
if err != nil {
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) {

mux.HandleFunc("/repos/o/r/code-scanning/alerts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"state": "open", "ref": "heads/master"})
testFormValues(t, r, values{"state": "open", "ref": "heads/master", "severity": "warning", "tool_name": "CodeQL"})
fmt.Fprint(w, `[{
"rule_id":"js/trivial-conditional",
"rule_severity":"warning",
Expand Down Expand Up @@ -512,7 +512,7 @@ func TestCodeScanningService_ListAlertsForRepo(t *testing.T) {
}]`)
})

opts := &AlertListOptions{State: "open", Ref: "heads/master"}
opts := &AlertListOptions{State: "open", Ref: "heads/master", Severity: "warning", ToolName: "CodeQL"}
ctx := context.Background()
alerts, _, err := client.CodeScanning.ListAlertsForRepo(ctx, "o", "r", opts)
if err != nil {
Expand Down
Loading