From 8c8f016003af8d41d582c16b6644474a3061bac0 Mon Sep 17 00:00:00 2001 From: Jan Guth Date: Tue, 5 Mar 2024 12:25:38 +0100 Subject: [PATCH] Add ListRunnersOptions to support all query parameters --- github/actions_runners.go | 10 ++++++++-- github/actions_runners_test.go | 16 ++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index c5c90279df5..2dd2eda22f3 100644 --- a/github/actions_runners.go +++ b/github/actions_runners.go @@ -151,12 +151,18 @@ type Runners struct { Runners []*Runner `json:"runners"` } +// ListRunnersOptions specifies the optional parameters to the ListRunners and ListOrganizationRunners methods. +type ListRunnersOptions struct { + Name string `url:"name,omitempty"` + ListOptions +} + // ListRunners lists all the self-hosted runners for a repository. // // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-self-hosted-runners-for-a-repository // //meta:operation GET /repos/{owner}/{repo}/actions/runners -func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListOptions) (*Runners, *Response, error) { +func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListRunnersOptions) (*Runners, *Response, error) { u := fmt.Sprintf("repos/%v/%v/actions/runners", owner, repo) u, err := addOptions(u, opts) if err != nil { @@ -290,7 +296,7 @@ func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-self-hosted-runners-for-an-organization // //meta:operation GET /orgs/{org}/actions/runners -func (s *ActionsService) ListOrganizationRunners(ctx context.Context, org string, opts *ListOptions) (*Runners, *Response, error) { +func (s *ActionsService) ListOrganizationRunners(ctx context.Context, org string, opts *ListRunnersOptions) (*Runners, *Response, error) { u := fmt.Sprintf("orgs/%v/actions/runners", org) u, err := addOptions(u, opts) if err != nil { diff --git a/github/actions_runners_test.go b/github/actions_runners_test.go index 581e459442d..a25be94881f 100644 --- a/github/actions_runners_test.go +++ b/github/actions_runners_test.go @@ -188,11 +188,14 @@ func TestActionsService_ListRunners(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runners", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testFormValues(t, r, values{"per_page": "2", "page": "2"}) - fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`) + testFormValues(t, r, values{"name": "MBP", "per_page": "2", "page": "2"}) + fmt.Fprint(w, `{"total_count":1,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"}]}`) }) - opts := &ListOptions{Page: 2, PerPage: 2} + opts := &ListRunnersOptions{ + Name: "MBP", + ListOptions: ListOptions{Page: 2, PerPage: 2}, + } ctx := context.Background() runners, _, err := client.Actions.ListRunners(ctx, "o", "r", opts) if err != nil { @@ -200,10 +203,9 @@ func TestActionsService_ListRunners(t *testing.T) { } want := &Runners{ - TotalCount: 2, + TotalCount: 1, Runners: []*Runner{ {ID: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")}, - {ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")}, }, } if !cmp.Equal(runners, want) { @@ -413,7 +415,9 @@ func TestActionsService_ListOrganizationRunners(t *testing.T) { fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`) }) - opts := &ListOptions{Page: 2, PerPage: 2} + opts := &ListRunnersOptions{ + ListOptions: ListOptions{Page: 2, PerPage: 2}, + } ctx := context.Background() runners, _, err := client.Actions.ListOrganizationRunners(ctx, "o", opts) if err != nil {