@@ -89,6 +89,210 @@ func TestCodeScanningService_UploadSarif(t *testing.T) {
8989 })
9090}
9191
92+ func TestCodeScanningService_ListAlertsForOrg (t * testing.T ) {
93+ client , mux , _ , teardown := setup ()
94+ defer teardown ()
95+
96+ mux .HandleFunc ("/orgs/o/code-scanning/alerts" , func (w http.ResponseWriter , r * http.Request ) {
97+ testMethod (t , r , "GET" )
98+ testFormValues (t , r , values {"state" : "open" , "ref" : "heads/master" })
99+ fmt .Fprint (w , `[{
100+ "repository": {
101+ "id": 1,
102+ "name": "n",
103+ "url": "url"
104+ },
105+ "rule_id":"js/trivial-conditional",
106+ "rule_severity":"warning",
107+ "rule_description":"Useless conditional",
108+ "tool": {
109+ "name": "CodeQL",
110+ "guid": null,
111+ "version": "1.4.0"
112+ },
113+ "rule": {
114+ "id": "js/trivial-conditional",
115+ "severity": "warning",
116+ "description": "Useless conditional",
117+ "name": "js/trivial-conditional",
118+ "full_description": "Expression has no effect",
119+ "help": "Expression has no effect"
120+ },
121+ "most_recent_instance": {
122+ "ref": "refs/heads/main",
123+ "state": "open",
124+ "commit_sha": "abcdefg12345",
125+ "message": {
126+ "text": "This path depends on a user-provided value."
127+ },
128+ "location": {
129+ "path": "spec-main/api-session-spec.ts",
130+ "start_line": 917,
131+ "end_line": 917,
132+ "start_column": 7,
133+ "end_column": 18
134+ },
135+ "classifications": [
136+ "test"
137+ ]
138+ },
139+ "created_at":"2020-05-06T12:00:00Z",
140+ "state":"open",
141+ "closed_by":null,
142+ "closed_at":null,
143+ "url":"https://api.github.com/repos/o/r/code-scanning/alerts/25",
144+ "html_url":"https://github.com/o/r/security/code-scanning/25"
145+ },
146+ {
147+ "rule_id":"js/useless-expression",
148+ "rule_severity":"warning",
149+ "rule_description":"Expression has no effect",
150+ "tool": {
151+ "name": "CodeQL",
152+ "guid": null,
153+ "version": "1.4.0"
154+ },
155+ "rule": {
156+ "id": "js/useless-expression",
157+ "severity": "warning",
158+ "description": "Expression has no effect",
159+ "name": "js/useless-expression",
160+ "full_description": "Expression has no effect",
161+ "help": "Expression has no effect"
162+ },
163+ "most_recent_instance": {
164+ "ref": "refs/heads/main",
165+ "state": "open",
166+ "commit_sha": "abcdefg12345",
167+ "message": {
168+ "text": "This path depends on a user-provided value."
169+ },
170+ "location": {
171+ "path": "spec-main/api-session-spec.ts",
172+ "start_line": 917,
173+ "end_line": 917,
174+ "start_column": 7,
175+ "end_column": 18
176+ },
177+ "classifications": [
178+ "test"
179+ ]
180+ },
181+ "created_at":"2020-05-06T12:00:00Z",
182+ "state":"open",
183+ "closed_by":null,
184+ "closed_at":null,
185+ "url":"https://api.github.com/repos/o/r/code-scanning/alerts/88",
186+ "html_url":"https://github.com/o/r/security/code-scanning/88"
187+ }]` )
188+ })
189+
190+ opts := & AlertListOptions {State : "open" , Ref : "heads/master" }
191+ ctx := context .Background ()
192+ alerts , _ , err := client .CodeScanning .ListAlertsForOrg (ctx , "o" , opts )
193+ if err != nil {
194+ t .Errorf ("CodeScanning.ListAlertsForOrg returned error: %v" , err )
195+ }
196+
197+ date := Timestamp {time .Date (2020 , time .May , 06 , 12 , 00 , 00 , 0 , time .UTC )}
198+ want := []* Alert {
199+ {
200+ Repository : & Repository {
201+ ID : Int64 (1 ),
202+ URL : String ("url" ),
203+ Name : String ("n" ),
204+ },
205+ RuleID : String ("js/trivial-conditional" ),
206+ RuleSeverity : String ("warning" ),
207+ RuleDescription : String ("Useless conditional" ),
208+ Tool : & Tool {Name : String ("CodeQL" ), GUID : nil , Version : String ("1.4.0" )},
209+ Rule : & Rule {
210+ ID : String ("js/trivial-conditional" ),
211+ Severity : String ("warning" ),
212+ Description : String ("Useless conditional" ),
213+ Name : String ("js/trivial-conditional" ),
214+ FullDescription : String ("Expression has no effect" ),
215+ Help : String ("Expression has no effect" ),
216+ },
217+ CreatedAt : & date ,
218+ State : String ("open" ),
219+ ClosedBy : nil ,
220+ ClosedAt : nil ,
221+ URL : String ("https://api.github.com/repos/o/r/code-scanning/alerts/25" ),
222+ HTMLURL : String ("https://github.com/o/r/security/code-scanning/25" ),
223+ MostRecentInstance : & MostRecentInstance {
224+ Ref : String ("refs/heads/main" ),
225+ State : String ("open" ),
226+ CommitSHA : String ("abcdefg12345" ),
227+ Message : & Message {
228+ Text : String ("This path depends on a user-provided value." ),
229+ },
230+ Location : & Location {
231+ Path : String ("spec-main/api-session-spec.ts" ),
232+ StartLine : Int (917 ),
233+ EndLine : Int (917 ),
234+ StartColumn : Int (7 ),
235+ EndColumn : Int (18 ),
236+ },
237+ Classifications : []string {"test" },
238+ },
239+ },
240+ {
241+ RuleID : String ("js/useless-expression" ),
242+ RuleSeverity : String ("warning" ),
243+ RuleDescription : String ("Expression has no effect" ),
244+ Tool : & Tool {Name : String ("CodeQL" ), GUID : nil , Version : String ("1.4.0" )},
245+ Rule : & Rule {
246+ ID : String ("js/useless-expression" ),
247+ Severity : String ("warning" ),
248+ Description : String ("Expression has no effect" ),
249+ Name : String ("js/useless-expression" ),
250+ FullDescription : String ("Expression has no effect" ),
251+ Help : String ("Expression has no effect" ),
252+ },
253+ CreatedAt : & date ,
254+ State : String ("open" ),
255+ ClosedBy : nil ,
256+ ClosedAt : nil ,
257+ URL : String ("https://api.github.com/repos/o/r/code-scanning/alerts/88" ),
258+ HTMLURL : String ("https://github.com/o/r/security/code-scanning/88" ),
259+ MostRecentInstance : & MostRecentInstance {
260+ Ref : String ("refs/heads/main" ),
261+ State : String ("open" ),
262+ CommitSHA : String ("abcdefg12345" ),
263+ Message : & Message {
264+ Text : String ("This path depends on a user-provided value." ),
265+ },
266+ Location : & Location {
267+ Path : String ("spec-main/api-session-spec.ts" ),
268+ StartLine : Int (917 ),
269+ EndLine : Int (917 ),
270+ StartColumn : Int (7 ),
271+ EndColumn : Int (18 ),
272+ },
273+ Classifications : []string {"test" },
274+ },
275+ },
276+ }
277+ if ! cmp .Equal (alerts , want ) {
278+ t .Errorf ("CodeScanning.ListAlertsForOrg returned %+v, want %+v" , * & alerts , * & want )
279+ }
280+
281+ const methodName = "ListAlertsForOrg"
282+ testBadOptions (t , methodName , func () (err error ) {
283+ _ , _ , err = client .CodeScanning .ListAlertsForOrg (ctx , "\n " , opts )
284+ return err
285+ })
286+
287+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
288+ got , resp , err := client .CodeScanning .ListAlertsForOrg (ctx , "o" , opts )
289+ if got != nil {
290+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
291+ }
292+ return resp , err
293+ })
294+ }
295+
92296func TestCodeScanningService_ListAlertsForRepo (t * testing.T ) {
93297 client , mux , _ , teardown := setup ()
94298 defer teardown ()
@@ -322,7 +526,7 @@ func TestCodeScanningService_GetAlert(t *testing.T) {
322526 "classifications": [
323527 "test"
324528 ]
325- },
529+ },
326530 "created_at":"2019-01-02T15:04:05Z",
327531 "state":"open",
328532 "closed_by":null,
0 commit comments