Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions github/actions_runner_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,32 @@ func (s *ActionsService) RemoveRepositoryAccessRunnerGroup(ctx context.Context,
return s.client.Do(ctx, req, nil)
}

// ListRunnerGroupHostedRunners lists the GitHub-hosted runners in an organization runner group.
//
// GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runner-groups#list-github-hosted-runners-in-a-group-for-an-organization
//
//meta:operation GET /orgs/{org}/actions/runner-groups/{runner_group_id}/hosted-runners
func (s *ActionsService) ListRunnerGroupHostedRunners(ctx context.Context, org string, groupID int64, opts *ListOptions) (*HostedRunners, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/hosted-runners", org, groupID)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

var runners *HostedRunners
resp, err := s.client.Do(ctx, req, &runners)
if err != nil {
return nil, resp, err
}

return runners, resp, nil
}

// ListRunnerGroupRunners lists self-hosted runners that are in a specific organization group.
//
// GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runner-groups#list-self-hosted-runners-in-a-group-for-an-organization
Expand Down
144 changes: 144 additions & 0 deletions github/actions_runner_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"net/http"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)
Expand Down Expand Up @@ -413,6 +414,149 @@ func TestActionsService_RemoveRepositoryAccessRunnerGroup(t *testing.T) {
})
}

func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/orgs/o/actions/runner-groups/2/hosted-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": 5,
"name": "My hosted ubuntu runner",
"runner_group_id": 2,
"platform": "linux-x64",
"image_details": {
"id": "ubuntu-20.04",
"size_gb": 86
},
"machine_size_details": {
"id": "4-core",
"cpu_cores": 4,
"memory_gb": 16,
"storage_gb": 150
},
"status": "Ready",
"maximum_runners": 10,
"public_ip_enabled": true,
"public_ips": [
{
"enabled": true,
"prefix": "20.80.208.150",
"length": 31
}
],
"last_active_on": "2023-04-26T15:23:37Z"
},
{
"id": 7,
"name": "My hosted Windows runner",
"runner_group_id": 2,
"platform": "win-x64",
"image_details": {
"id": "windows-latest",
"size_gb": 256
},
"machine_size_details": {
"id": "8-core",
"cpu_cores": 8,
"memory_gb": 32,
"storage_gb": 300
},
"status": "Ready",
"maximum_runners": 20,
"public_ip_enabled": false,
"public_ips": [],
"last_active_on": "2023-04-26T15:23:37Z"
}
]
}`)
})

opts := &ListOptions{Page: 2, PerPage: 2}
ctx := t.Context()
runners, _, err := client.Actions.ListRunnerGroupHostedRunners(ctx, "o", 2, opts)
if err != nil {
t.Errorf("Actions.ListRunnerGroupHostedRunners returned error: %v", err)
}

lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}

want := &HostedRunners{
TotalCount: 2,
Runners: []*HostedRunner{
{
ID: Ptr(int64(5)),
Name: Ptr("My hosted ubuntu runner"),
RunnerGroupID: Ptr(int64(2)),
Platform: Ptr("linux-x64"),
ImageDetails: &HostedRunnerImageDetail{
ID: Ptr("ubuntu-20.04"),
SizeGB: Ptr(int64(86)),
},
MachineSizeDetails: &HostedRunnerMachineSpec{
ID: "4-core",
CPUCores: 4,
MemoryGB: 16,
StorageGB: 150,
},
Status: Ptr("Ready"),
MaximumRunners: Ptr(int64(10)),
PublicIPEnabled: Ptr(true),
PublicIPs: []*HostedRunnerPublicIP{
{
Enabled: true,
Prefix: "20.80.208.150",
Length: 31,
},
},
LastActiveOn: Ptr(lastActiveOn),
},
{
ID: Ptr(int64(7)),
Name: Ptr("My hosted Windows runner"),
RunnerGroupID: Ptr(int64(2)),
Platform: Ptr("win-x64"),
ImageDetails: &HostedRunnerImageDetail{
ID: Ptr("windows-latest"),
SizeGB: Ptr(int64(256)),
},
MachineSizeDetails: &HostedRunnerMachineSpec{
ID: "8-core",
CPUCores: 8,
MemoryGB: 32,
StorageGB: 300,
},
Status: Ptr("Ready"),
MaximumRunners: Ptr(int64(20)),
PublicIPEnabled: Ptr(false),
PublicIPs: []*HostedRunnerPublicIP{},
LastActiveOn: Ptr(lastActiveOn),
},
},
}
if !cmp.Equal(runners, want) {
t.Errorf("Actions.ListRunnerGroupHostedRunners returned %+v, want %+v", runners, want)
}

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

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

func TestActionsService_ListRunnerGroupRunners(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down
35 changes: 35 additions & 0 deletions github/github-iterators.go

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

72 changes: 72 additions & 0 deletions github/github-iterators_test.go

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

Loading