From 765fbf8ee9545274c21d03bb88b6eac502b60154 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 ++++++++++------ github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 10 ++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index c5c90279df5..c4ae48232ec 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..f425e8af7b0 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: String("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 { diff --git a/github/github-accessors.go b/github/github-accessors.go index 89728d38df9..4e9a5982060 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10742,6 +10742,14 @@ func (l *ListRepositories) GetTotalCount() int { return *l.TotalCount } +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (l *ListRunnersOptions) GetName() string { + if l == nil || l.Name == nil { + return "" + } + return *l.Name +} + // GetCount returns the Count field if it's non-nil, zero value otherwise. func (l *ListSCIMProvisionedIdentitiesOptions) GetCount() int { if l == nil || l.Count == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 1dcb4dc2bb9..76a4a7e1291 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -12564,6 +12564,16 @@ func TestListRepositories_GetTotalCount(tt *testing.T) { l.GetTotalCount() } +func TestListRunnersOptions_GetName(tt *testing.T) { + var zeroValue string + l := &ListRunnersOptions{Name: &zeroValue} + l.GetName() + l = &ListRunnersOptions{} + l.GetName() + l = nil + l.GetName() +} + func TestListSCIMProvisionedIdentitiesOptions_GetCount(tt *testing.T) { var zeroValue int l := &ListSCIMProvisionedIdentitiesOptions{Count: &zeroValue}