Skip to content

Commit

Permalink
Add ListRunnersOptions to support all query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fentas committed Mar 5, 2024
1 parent 0e3ab58 commit 765fbf8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
10 changes: 8 additions & 2 deletions github/actions_runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions github/actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,24 @@ 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 {
t.Errorf("Actions.ListRunners returned error: %v", err)
}

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) {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 765fbf8

Please sign in to comment.