From 3f8a64020bf6aeff2f5cc8be7776fee7996947fd Mon Sep 17 00:00:00 2001 From: GaneshKumar Date: Mon, 21 Jun 2021 18:19:01 -0400 Subject: [PATCH 1/3] Fixes Code Scanning Alert tool field --- github/code-scanning.go | 8 +++++++- github/code-scanning_test.go | 24 ++++++++++++++++------ github/github-accessors.go | 34 +++++++++++++++++++++++++++----- github/github-accessors_test.go | 35 +++++++++++++++++++++++++++++---- 4 files changed, 85 insertions(+), 16 deletions(-) diff --git a/github/code-scanning.go b/github/code-scanning.go index 9eb711cf437..a43b1979a46 100644 --- a/github/code-scanning.go +++ b/github/code-scanning.go @@ -18,11 +18,17 @@ import ( // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/code-scanning/ type CodeScanningService service +type Tool struct { + Name *string `json:"name,omitempty"` + GUID *string `json:"guid,omitempty"` + Version *string `json:"version,omitempty"` +} + type Alert struct { RuleID *string `json:"rule_id,omitempty"` RuleSeverity *string `json:"rule_severity,omitempty"` RuleDescription *string `json:"rule_description,omitempty"` - Tool *string `json:"tool,omitempty"` + Tool *Tool `json:"tool,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` Open *bool `json:"open,omitempty"` ClosedBy *User `json:"closed_by,omitempty"` diff --git a/github/code-scanning_test.go b/github/code-scanning_test.go index be9fb3de4c3..2e89856535e 100644 --- a/github/code-scanning_test.go +++ b/github/code-scanning_test.go @@ -64,7 +64,11 @@ func TestActionsService_ListAlertsForRepo(t *testing.T) { "rule_id":"js/trivial-conditional", "rule_severity":"warning", "rule_description":"Useless conditional", - "tool":"CodeQL", + "tool": { + "name": "CodeQL", + "guid": null, + "version": "1.4.0" + }, "created_at":"2020-05-06T12:00:00Z", "open":true, "closed_by":null, @@ -76,7 +80,11 @@ func TestActionsService_ListAlertsForRepo(t *testing.T) { "rule_id":"js/useless-expression", "rule_severity":"warning", "rule_description":"Expression has no effect", - "tool":"CodeQL", + "tool": { + "name": "CodeQL", + "guid": null, + "version": "1.4.0" + }, "created_at":"2020-05-06T12:00:00Z", "open":true, "closed_by":null, @@ -99,7 +107,7 @@ func TestActionsService_ListAlertsForRepo(t *testing.T) { RuleID: String("js/trivial-conditional"), RuleSeverity: String("warning"), RuleDescription: String("Useless conditional"), - Tool: String("CodeQL"), + Tool: &Tool{Name: String("CodeQL"), GUID: nil, Version: String("1.4.0")}, CreatedAt: &date, Open: Bool(true), ClosedBy: nil, @@ -111,7 +119,7 @@ func TestActionsService_ListAlertsForRepo(t *testing.T) { RuleID: String("js/useless-expression"), RuleSeverity: String("warning"), RuleDescription: String("Expression has no effect"), - Tool: String("CodeQL"), + Tool: &Tool{Name: String("CodeQL"), GUID: nil, Version: String("1.4.0")}, CreatedAt: &date, Open: Bool(true), ClosedBy: nil, @@ -148,7 +156,11 @@ func TestActionsService_GetAlert(t *testing.T) { fmt.Fprint(w, `{"rule_id":"js/useless-expression", "rule_severity":"warning", "rule_description":"Expression has no effect", - "tool":"CodeQL", + "tool": { + "name": "CodeQL", + "guid": null, + "version": "1.4.0" + }, "created_at":"2019-01-02T15:04:05Z", "open":true, "closed_by":null, @@ -168,7 +180,7 @@ func TestActionsService_GetAlert(t *testing.T) { RuleID: String("js/useless-expression"), RuleSeverity: String("warning"), RuleDescription: String("Expression has no effect"), - Tool: String("CodeQL"), + Tool: &Tool{Name: String("CodeQL"), GUID: nil, Version: String("1.4.0")}, CreatedAt: &date, Open: Bool(true), ClosedBy: nil, diff --git a/github/github-accessors.go b/github/github-accessors.go index 1c17384eac0..5e3b8ac1711 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -212,12 +212,12 @@ func (a *Alert) GetRuleSeverity() string { return *a.RuleSeverity } -// GetTool returns the Tool field if it's non-nil, zero value otherwise. -func (a *Alert) GetTool() string { - if a == nil || a.Tool == nil { - return "" +// GetTool returns the Tool field. +func (a *Alert) GetTool() *Tool { + if a == nil { + return nil } - return *a.Tool + return a.Tool } // GetURL returns the URL field if it's non-nil, zero value otherwise. @@ -14932,6 +14932,30 @@ func (t *Timeline) GetURL() string { return *t.URL } +// GetGUID returns the GUID field if it's non-nil, zero value otherwise. +func (t *Tool) GetGUID() string { + if t == nil || t.GUID == nil { + return "" + } + return *t.GUID +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (t *Tool) GetName() string { + if t == nil || t.Name == nil { + return "" + } + return *t.Name +} + +// GetVersion returns the Version field if it's non-nil, zero value otherwise. +func (t *Tool) GetVersion() string { + if t == nil || t.Version == nil { + return "" + } + return *t.Version +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (t *TopicResult) GetCreatedAt() Timestamp { if t == nil || t.CreatedAt == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 750c6a40f8f..50a3a327a43 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -231,10 +231,7 @@ func TestAlert_GetRuleSeverity(tt *testing.T) { } func TestAlert_GetTool(tt *testing.T) { - var zeroValue string - a := &Alert{Tool: &zeroValue} - a.GetTool() - a = &Alert{} + a := &Alert{} a.GetTool() a = nil a.GetTool() @@ -17481,6 +17478,36 @@ func TestTimeline_GetURL(tt *testing.T) { t.GetURL() } +func TestTool_GetGUID(tt *testing.T) { + var zeroValue string + t := &Tool{GUID: &zeroValue} + t.GetGUID() + t = &Tool{} + t.GetGUID() + t = nil + t.GetGUID() +} + +func TestTool_GetName(tt *testing.T) { + var zeroValue string + t := &Tool{Name: &zeroValue} + t.GetName() + t = &Tool{} + t.GetName() + t = nil + t.GetName() +} + +func TestTool_GetVersion(tt *testing.T) { + var zeroValue string + t := &Tool{Version: &zeroValue} + t.GetVersion() + t = &Tool{} + t.GetVersion() + t = nil + t.GetVersion() +} + func TestTopicResult_GetCreatedAt(tt *testing.T) { var zeroValue Timestamp t := &TopicResult{CreatedAt: &zeroValue} From 2e9db798f1ea2b50f1cce2f0940057c94a491b69 Mon Sep 17 00:00:00 2001 From: ganeshkumarsv <53483484+ganeshkumarsv@users.noreply.github.com> Date: Mon, 21 Jun 2021 19:12:18 -0400 Subject: [PATCH 2/3] Update github/code-scanning.go Co-authored-by: Stephen --- github/code-scanning.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/github/code-scanning.go b/github/code-scanning.go index a43b1979a46..020b0da0d5c 100644 --- a/github/code-scanning.go +++ b/github/code-scanning.go @@ -24,6 +24,9 @@ type Tool struct { Version *string `json:"version,omitempty"` } +// Alert represents an individual GitHub Code Scanning Alert on a single repository. +// +// GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-alerts-for-a-repository type Alert struct { RuleID *string `json:"rule_id,omitempty"` RuleSeverity *string `json:"rule_severity,omitempty"` From ce450a9aa87decce110d30971ab37adf5b9d139c Mon Sep 17 00:00:00 2001 From: ganeshkumarsv <53483484+ganeshkumarsv@users.noreply.github.com> Date: Mon, 21 Jun 2021 19:12:29 -0400 Subject: [PATCH 3/3] Update github/code-scanning.go Co-authored-by: Stephen --- github/code-scanning.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/github/code-scanning.go b/github/code-scanning.go index 020b0da0d5c..8602c446322 100644 --- a/github/code-scanning.go +++ b/github/code-scanning.go @@ -18,6 +18,9 @@ import ( // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/code-scanning/ type CodeScanningService service +// Tool represents the tool used to generate a GitHub Code Scanning Alert. +// +// GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-alerts-for-a-repository type Tool struct { Name *string `json:"name,omitempty"` GUID *string `json:"guid,omitempty"`