@@ -235,42 +235,59 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) {
235235 client , mux , _ := setup (t )
236236
237237 event := CreateWorkflowDispatchEventRequest {
238- Ref : "d4cfb6e7" ,
238+ Ref : "d4cfb6e7" ,
239+ ReturnRunDetails : Ptr (true ),
239240 Inputs : map [string ]any {
240241 "key" : "value" ,
241242 },
242243 }
243- mux .HandleFunc ("/repos/o/r/actions/workflows/72844/dispatches" , func (_ http.ResponseWriter , r * http.Request ) {
244+ mux .HandleFunc ("/repos/o/r/actions/workflows/72844/dispatches" , func (w http.ResponseWriter , r * http.Request ) {
244245 var v CreateWorkflowDispatchEventRequest
245246 assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
246247
247248 testMethod (t , r , "POST" )
248249 if ! cmp .Equal (v , event ) {
249250 t .Errorf ("Request body = %+v, want %+v" , v , event )
250251 }
252+
253+ w .WriteHeader (http .StatusOK )
254+ fmt .Fprint (w , `{"workflow_run_id":1,"run_url":"https://api.github.com/repos/o/r/actions/runs/1","html_url":"https://github.com/o/r/actions/runs/1"}` )
251255 })
252256
253257 ctx := t .Context ()
254- _ , err := client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
258+ dispatchResponse , _ , err := client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
255259 if err != nil {
256260 t .Errorf ("Actions.CreateWorkflowDispatchEventByID returned error: %v" , err )
257261 }
258262
263+ want := & WorkflowDispatchRunDetails {
264+ WorkflowRunID : Ptr (int64 (1 )),
265+ RunURL : Ptr ("https://api.github.com/repos/o/r/actions/runs/1" ),
266+ HTMLURL : Ptr ("https://github.com/o/r/actions/runs/1" ),
267+ }
268+ if ! cmp .Equal (dispatchResponse , want ) {
269+ t .Errorf ("Actions.CreateWorkflowDispatchEventByID = %+v, want %+v" , dispatchResponse , want )
270+ }
271+
259272 // Test s.client.NewRequest failure
260273 client .BaseURL .Path = ""
261- _ , err = client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
274+ _ , _ , err = client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
262275 if err == nil {
263276 t .Error ("client.BaseURL.Path='' CreateWorkflowDispatchEventByID err = nil, want error" )
264277 }
265278
266279 const methodName = "CreateWorkflowDispatchEventByID"
267280 testBadOptions (t , methodName , func () (err error ) {
268- _ , err = client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
281+ _ , _ , err = client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
269282 return err
270283 })
271284
272285 testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
273- return client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
286+ got , resp , err := client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
287+ if got != nil {
288+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
289+ }
290+ return resp , err
274291 })
275292}
276293
@@ -279,43 +296,126 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName(t *testing.T) {
279296 client , mux , _ := setup (t )
280297
281298 event := CreateWorkflowDispatchEventRequest {
282- Ref : "d4cfb6e7" ,
299+ Ref : "d4cfb6e7" ,
300+ ReturnRunDetails : Ptr (true ),
283301 Inputs : map [string ]any {
284302 "key" : "value" ,
285303 },
286304 }
287- mux .HandleFunc ("/repos/o/r/actions/workflows/main.yml/dispatches" , func (_ http.ResponseWriter , r * http.Request ) {
305+ mux .HandleFunc ("/repos/o/r/actions/workflows/main.yml/dispatches" , func (w http.ResponseWriter , r * http.Request ) {
288306 var v CreateWorkflowDispatchEventRequest
289307 assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
290308
291309 testMethod (t , r , "POST" )
292310 if ! cmp .Equal (v , event ) {
293311 t .Errorf ("Request body = %+v, want %+v" , v , event )
294312 }
313+
314+ w .WriteHeader (http .StatusOK )
315+ fmt .Fprint (w , `{"workflow_run_id":1,"run_url":"https://api.github.com/repos/o/r/actions/runs/1","html_url":"https://github.com/o/r/actions/runs/1"}` )
295316 })
296317
297318 ctx := t .Context ()
298- _ , err := client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
319+ dispatchResponse , _ , err := client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
299320 if err != nil {
300321 t .Errorf ("Actions.CreateWorkflowDispatchEventByFileName returned error: %v" , err )
301322 }
302323
324+ want := & WorkflowDispatchRunDetails {
325+ WorkflowRunID : Ptr (int64 (1 )),
326+ RunURL : Ptr ("https://api.github.com/repos/o/r/actions/runs/1" ),
327+ HTMLURL : Ptr ("https://github.com/o/r/actions/runs/1" ),
328+ }
329+ if ! cmp .Equal (dispatchResponse , want ) {
330+ t .Errorf ("Actions.CreateWorkflowDispatchEventByFileName = %+v, want %+v" , dispatchResponse , want )
331+ }
332+
303333 // Test s.client.NewRequest failure
304334 client .BaseURL .Path = ""
305- _ , err = client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
335+ _ , _ , err = client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
306336 if err == nil {
307337 t .Error ("client.BaseURL.Path='' CreateWorkflowDispatchEventByFileName err = nil, want error" )
308338 }
309339
310340 const methodName = "CreateWorkflowDispatchEventByFileName"
311341 testBadOptions (t , methodName , func () (err error ) {
312- _ , err = client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
342+ _ , _ , err = client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
313343 return err
314344 })
315345
316346 testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
317- return client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
347+ got , resp , err := client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
348+ if got != nil {
349+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
350+ }
351+ return resp , err
352+ })
353+ }
354+
355+ func TestActionsService_CreateWorkflowDispatchEventByID_noRunDetails (t * testing.T ) {
356+ t .Parallel ()
357+ client , mux , _ := setup (t )
358+
359+ event := CreateWorkflowDispatchEventRequest {
360+ Ref : "d4cfb6e7" ,
361+ Inputs : map [string ]any {
362+ "key" : "value" ,
363+ },
364+ }
365+ mux .HandleFunc ("/repos/o/r/actions/workflows/72844/dispatches" , func (w http.ResponseWriter , r * http.Request ) {
366+ var v CreateWorkflowDispatchEventRequest
367+ assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
368+
369+ testMethod (t , r , "POST" )
370+ if ! cmp .Equal (v , event ) {
371+ t .Errorf ("Request body = %+v, want %+v" , v , event )
372+ }
373+
374+ w .WriteHeader (http .StatusNoContent )
375+ })
376+
377+ ctx := t .Context ()
378+ dispatchResponse , _ , err := client .Actions .CreateWorkflowDispatchEventByID (ctx , "o" , "r" , 72844 , event )
379+ if err != nil {
380+ t .Errorf ("Actions.CreateWorkflowDispatchEventByID returned error: %v" , err )
381+ }
382+
383+ if dispatchResponse != nil {
384+ t .Errorf ("Actions.CreateWorkflowDispatchEventByID = %+v, want nil" , dispatchResponse )
385+ }
386+ }
387+
388+ func TestActionsService_CreateWorkflowDispatchEventByFileName_noRunDetails (t * testing.T ) {
389+ t .Parallel ()
390+ client , mux , _ := setup (t )
391+
392+ event := CreateWorkflowDispatchEventRequest {
393+ Ref : "d4cfb6e7" ,
394+ Inputs : map [string ]any {
395+ "key" : "value" ,
396+ },
397+ }
398+ mux .HandleFunc ("/repos/o/r/actions/workflows/main.yml/dispatches" , func (w http.ResponseWriter , r * http.Request ) {
399+ var v CreateWorkflowDispatchEventRequest
400+ assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
401+
402+ testMethod (t , r , "POST" )
403+ if ! cmp .Equal (v , event ) {
404+ t .Errorf ("Request body = %+v, want %+v" , v , event )
405+ }
406+
407+ w .WriteHeader (http .StatusNoContent )
318408 })
409+
410+ ctx := t .Context ()
411+ dispatchResponse , _ , err := client .Actions .CreateWorkflowDispatchEventByFileName (ctx , "o" , "r" , "main.yml" , event )
412+ if err != nil {
413+ t .Errorf ("Actions.CreateWorkflowDispatchEventByFileName returned error: %v" , err )
414+ }
415+
416+ if dispatchResponse != nil {
417+ t .Errorf ("Actions.CreateWorkflowDispatchEventByFileName = %+v, want nil" , dispatchResponse )
418+ }
319419}
320420
321421func TestActionsService_EnableWorkflowByID (t * testing.T ) {
0 commit comments