From 3b66fc4fd3de7d49a5ee0cee23b941c152f29934 Mon Sep 17 00:00:00 2001 From: Jarek Porzucek <17789797+jporzucek@users.noreply.github.com> Date: Thu, 27 Jul 2023 13:43:30 +0200 Subject: [PATCH 1/3] Add new query params for AlertListOptions --- github/code-scanning.go | 6 ++++++ github/code-scanning_test.go | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/github/code-scanning.go b/github/code-scanning.go index e4a6abeba37..09c03647876 100644 --- a/github/code-scanning.go +++ b/github/code-scanning.go @@ -122,6 +122,12 @@ type AlertListOptions struct { // Return code scanning alerts for a specific branch reference. The ref must be formatted as heads/. 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 diff --git a/github/code-scanning_test.go b/github/code-scanning_test.go index 29c0b617b84..20d4817d3f1 100644 --- a/github/code-scanning_test.go +++ b/github/code-scanning_test.go @@ -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, @@ -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 { @@ -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, @@ -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 { @@ -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", @@ -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 { From 244c00751778e37f60ac800482748ec938a22d44 Mon Sep 17 00:00:00 2001 From: Jarek Porzucek <17789797+jporzucek@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:49:45 +0200 Subject: [PATCH 2/3] Switch to ListOptions pagination for Dependabot alerts --- github/dependabot_alerts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/dependabot_alerts.go b/github/dependabot_alerts.go index 7b5d53b3939..3041e0930c7 100644 --- a/github/dependabot_alerts.go +++ b/github/dependabot_alerts.go @@ -76,7 +76,7 @@ type ListAlertsOptions struct { Sort *string `url:"sort,omitempty"` Direction *string `url:"direction,omitempty"` - ListCursorOptions + ListOptions } func (s *DependabotService) listAlerts(ctx context.Context, url string, opts *ListAlertsOptions) ([]*DependabotAlert, *Response, error) { From 3c2420fffacf9a1504f7fbb1fdeefc01e572a15e Mon Sep 17 00:00:00 2001 From: Jarek Porzucek <17789797+jporzucek@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:11:41 +0200 Subject: [PATCH 3/3] Keep both pagination options --- github/dependabot_alerts.go | 1 + 1 file changed, 1 insertion(+) diff --git a/github/dependabot_alerts.go b/github/dependabot_alerts.go index 3041e0930c7..a55f540f1be 100644 --- a/github/dependabot_alerts.go +++ b/github/dependabot_alerts.go @@ -77,6 +77,7 @@ type ListAlertsOptions struct { Direction *string `url:"direction,omitempty"` ListOptions + ListCursorOptions } func (s *DependabotService) listAlerts(ctx context.Context, url string, opts *ListAlertsOptions) ([]*DependabotAlert, *Response, error) {