Skip to content

Commit 098e698

Browse files
authored
Add new query params for AlertListOptions (#2848)
Fixes: #2847.
1 parent 7e3bb17 commit 098e698

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

github/code-scanning.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ type AlertListOptions struct {
122122
// Return code scanning alerts for a specific branch reference. The ref must be formatted as heads/<branch name>.
123123
Ref string `url:"ref,omitempty"`
124124

125+
// If specified, only code scanning alerts with this severity will be returned. Possible values are: critical, high, medium, low, warning, note, error.
126+
Severity string `url:"severity,omitempty"`
127+
128+
// The name of a code scanning tool. Only results by this tool will be listed.
129+
ToolName string `url:"tool_name,omitempty"`
130+
125131
ListCursorOptions
126132

127133
// Add ListOptions so offset pagination with integer type "page" query parameter is accepted

github/code-scanning_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) {
9595

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

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

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

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

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

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

0 commit comments

Comments
 (0)