Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add ListRunnersOptions to support all query parameters #3094

Merged
merged 2 commits into from May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions github/actions_runners.go
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
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.