diff --git a/github/actions_runners.go b/github/actions_runners.go index c5c90279df..c4ae48232e 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 581e459442..f425e8af7b 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 390ae086d3..a0ecef5dda 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10766,6 +10766,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 8fafe9a218..4cc49f7d7a 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -12588,6 +12588,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}