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

Support query parameter visible_to_repository in ListOrganizationRunnerGroups #2329

Merged
merged 5 commits into from May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 19 additions & 2 deletions github/actions_runner_groups.go
Expand Up @@ -61,10 +61,27 @@ type SetRunnerGroupRunnersRequest struct {
Runners []int64 `json:"runners"`
}

// ListOrganizationRunnerGroups lists all self-hosted runner groups configured in an organization.
// ListOrgRunnerGroupOptions extend ListOptions to have the optional parameters VisibleToRepository
TingluoHuang marked this conversation as resolved.
Show resolved Hide resolved
type ListOrgRunnerGroupOptions struct {
ListOptions

// Only return runner groups that are allowed to be used by this repository.
VisibleToRepository string `url:"visible_to_repository,omitempty"`
}

// ListOrganizationRunnerGroups is a wrapper around ListOrganizationRunnerGroupsWithOptions to avoid breaking existing client's code.
func (s *ActionsService) ListOrganizationRunnerGroups(ctx context.Context, org string, opts *ListOptions) (*RunnerGroups, *Response, error) {
TingluoHuang marked this conversation as resolved.
Show resolved Hide resolved
listOpts := &ListOrgRunnerGroupOptions{}
if opts != nil {
listOpts.ListOptions = *opts
}
return s.ListOrganizationRunnerGroupsWithOptions(ctx, org, listOpts)
}

// ListOrganizationRunnerGroupsWithOptions lists all self-hosted runner groups configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#list-self-hosted-runner-groups-for-an-organization
func (s *ActionsService) ListOrganizationRunnerGroups(ctx context.Context, org string, opts *ListOptions) (*RunnerGroups, *Response, error) {
func (s *ActionsService) ListOrganizationRunnerGroupsWithOptions(ctx context.Context, org string, opts *ListOrgRunnerGroupOptions) (*RunnerGroups, *Response, error) {
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
u := fmt.Sprintf("orgs/%v/actions/runner-groups", org)
u, err := addOptions(u, opts)
if err != nil {
Expand Down
44 changes: 44 additions & 0 deletions github/actions_runner_groups_test.go
Expand Up @@ -58,6 +58,50 @@ func TestActionsService_ListOrganizationRunnerGroups(t *testing.T) {
})
}

func TestActionsService_ListOrganizationRunnerGroupsWithOptions(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/orgs/o/actions/runner-groups", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"per_page": "2", "page": "2", "visible_to_repository": "github"})
fmt.Fprint(w, `{"total_count":3,"runner_groups":[{"id":1,"name":"Default","visibility":"all","default":true,"runners_url":"https://api.github.com/orgs/octo-org/actions/runner_groups/1/runners","inherited":false,"allows_public_repositories":true},{"id":2,"name":"octo-runner-group","visibility":"selected","default":false,"selected_repositories_url":"https://api.github.com/orgs/octo-org/actions/runner_groups/2/repositories","runners_url":"https://api.github.com/orgs/octo-org/actions/runner_groups/2/runners","inherited":true,"allows_public_repositories":true},{"id":3,"name":"expensive-hardware","visibility":"private","default":false,"runners_url":"https://api.github.com/orgs/octo-org/actions/runner_groups/3/runners","inherited":false,"allows_public_repositories":true}]}`)
})

opts := &ListOrgRunnerGroupOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}, VisibleToRepository: "github"}
ctx := context.Background()
groups, _, err := client.Actions.ListOrganizationRunnerGroupsWithOptions(ctx, "o", opts)
if err != nil {
t.Errorf("Actions.ListOrganizationRunnerGroupsWithOptions returned error: %v", err)
}

want := &RunnerGroups{
TotalCount: 3,
RunnerGroups: []*RunnerGroup{
{ID: Int64(1), Name: String("Default"), Visibility: String("all"), Default: Bool(true), RunnersURL: String("https://api.github.com/orgs/octo-org/actions/runner_groups/1/runners"), Inherited: Bool(false), AllowsPublicRepositories: Bool(true)},
{ID: Int64(2), Name: String("octo-runner-group"), Visibility: String("selected"), Default: Bool(false), SelectedRepositoriesURL: String("https://api.github.com/orgs/octo-org/actions/runner_groups/2/repositories"), RunnersURL: String("https://api.github.com/orgs/octo-org/actions/runner_groups/2/runners"), Inherited: Bool(true), AllowsPublicRepositories: Bool(true)},
{ID: Int64(3), Name: String("expensive-hardware"), Visibility: String("private"), Default: Bool(false), RunnersURL: String("https://api.github.com/orgs/octo-org/actions/runner_groups/3/runners"), Inherited: Bool(false), AllowsPublicRepositories: Bool(true)},
},
}
if !cmp.Equal(groups, want) {
t.Errorf("Actions.ListOrganizationRunnerGroupsWithOptions returned %+v, want %+v", groups, want)
}

const methodName = "ListOrganizationRunnerGroupsWithOptions"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.ListOrganizationRunnerGroupsWithOptions(ctx, "\n", opts)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.ListOrganizationRunnerGroupsWithOptions(ctx, "o", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestActionsService_GetOrganizationRunnerGroup(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down