Skip to content

Commit c903947

Browse files
committed
Merge branch 'master' into master
2 parents 66ce726 + 879c78f commit c903947

16 files changed

+719
-54
lines changed

github/actions_workflows.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,20 @@ type CreateWorkflowDispatchEventRequest struct {
5151
// Ref is required when creating a workflow dispatch event.
5252
Ref string `json:"ref"`
5353
// Inputs represents input keys and values configured in the workflow file.
54-
// The maximum number of properties is 10.
54+
// The maximum number of properties is 25.
5555
// Default: Any default properties configured in the workflow file will be used when `inputs` are omitted.
5656
Inputs map[string]any `json:"inputs,omitempty"`
57+
// ReturnRunDetails specifies whether the response should include
58+
// the workflow run ID and URLs.
59+
ReturnRunDetails *bool `json:"return_run_details,omitempty"`
60+
}
61+
62+
// WorkflowDispatchRunDetails represents the response from creating
63+
// a workflow dispatch event when ReturnRunDetails is set to true.
64+
type WorkflowDispatchRunDetails struct {
65+
WorkflowRunID *int64 `json:"workflow_run_id,omitempty"`
66+
RunURL *string `json:"run_url,omitempty"`
67+
HTMLURL *string `json:"html_url,omitempty"`
5768
}
5869

5970
// WorkflowsPermissions represents the permissions for workflows in a repository.
@@ -191,7 +202,7 @@ func (s *ActionsService) getWorkflowUsage(ctx context.Context, url string) (*Wor
191202
// GitHub API docs: https://docs.github.com/rest/actions/workflows#create-a-workflow-dispatch-event
192203
//
193204
//meta:operation POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
194-
func (s *ActionsService) CreateWorkflowDispatchEventByID(ctx context.Context, owner, repo string, workflowID int64, event CreateWorkflowDispatchEventRequest) (*Response, error) {
205+
func (s *ActionsService) CreateWorkflowDispatchEventByID(ctx context.Context, owner, repo string, workflowID int64, event CreateWorkflowDispatchEventRequest) (*WorkflowDispatchRunDetails, *Response, error) {
195206
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/dispatches", owner, repo, workflowID)
196207

197208
return s.createWorkflowDispatchEvent(ctx, u, &event)
@@ -202,19 +213,25 @@ func (s *ActionsService) CreateWorkflowDispatchEventByID(ctx context.Context, ow
202213
// GitHub API docs: https://docs.github.com/rest/actions/workflows#create-a-workflow-dispatch-event
203214
//
204215
//meta:operation POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
205-
func (s *ActionsService) CreateWorkflowDispatchEventByFileName(ctx context.Context, owner, repo, workflowFileName string, event CreateWorkflowDispatchEventRequest) (*Response, error) {
216+
func (s *ActionsService) CreateWorkflowDispatchEventByFileName(ctx context.Context, owner, repo, workflowFileName string, event CreateWorkflowDispatchEventRequest) (*WorkflowDispatchRunDetails, *Response, error) {
206217
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/dispatches", owner, repo, workflowFileName)
207218

208219
return s.createWorkflowDispatchEvent(ctx, u, &event)
209220
}
210221

211-
func (s *ActionsService) createWorkflowDispatchEvent(ctx context.Context, url string, event *CreateWorkflowDispatchEventRequest) (*Response, error) {
222+
func (s *ActionsService) createWorkflowDispatchEvent(ctx context.Context, url string, event *CreateWorkflowDispatchEventRequest) (*WorkflowDispatchRunDetails, *Response, error) {
212223
req, err := s.client.NewRequest("POST", url, event)
213224
if err != nil {
214-
return nil, err
225+
return nil, nil, err
215226
}
216227

217-
return s.client.Do(ctx, req, nil)
228+
var dispatchRunDetails *WorkflowDispatchRunDetails
229+
resp, err := s.client.Do(ctx, req, &dispatchRunDetails)
230+
if err != nil {
231+
return nil, resp, err
232+
}
233+
234+
return dispatchRunDetails, resp, nil
218235
}
219236

220237
// EnableWorkflowByID enables a workflow and sets the state of the workflow to "active".

github/actions_workflows_test.go

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

321421
func TestActionsService_EnableWorkflowByID(t *testing.T) {

github/enterprise_apps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestEnterpriseService_UpdateAppInstallationRepositories(t *testing.T) {
5151
client, mux, _ := setup(t)
5252

5353
input := UpdateAppInstallationRepositoriesOptions{
54-
RepositorySelection: String("selected"),
54+
RepositorySelection: Ptr("selected"),
5555
SelectedRepositoryIDs: []int64{1, 2},
5656
}
5757

github/github-accessors.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)