Skip to content

Commit 247ddc3

Browse files
authored
feat: Add ListRunnerGroupHostedRunners for org runner groups (#4100)
1 parent 657976b commit 247ddc3

File tree

4 files changed

+277
-0
lines changed

4 files changed

+277
-0
lines changed

github/actions_runner_groups.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,32 @@ func (s *ActionsService) RemoveRepositoryAccessRunnerGroup(ctx context.Context,
265265
return s.client.Do(ctx, req, nil)
266266
}
267267

268+
// ListRunnerGroupHostedRunners lists the GitHub-hosted runners in an organization runner group.
269+
//
270+
// GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runner-groups#list-github-hosted-runners-in-a-group-for-an-organization
271+
//
272+
//meta:operation GET /orgs/{org}/actions/runner-groups/{runner_group_id}/hosted-runners
273+
func (s *ActionsService) ListRunnerGroupHostedRunners(ctx context.Context, org string, groupID int64, opts *ListOptions) (*HostedRunners, *Response, error) {
274+
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/hosted-runners", org, groupID)
275+
u, err := addOptions(u, opts)
276+
if err != nil {
277+
return nil, nil, err
278+
}
279+
280+
req, err := s.client.NewRequest("GET", u, nil)
281+
if err != nil {
282+
return nil, nil, err
283+
}
284+
285+
var runners *HostedRunners
286+
resp, err := s.client.Do(ctx, req, &runners)
287+
if err != nil {
288+
return nil, resp, err
289+
}
290+
291+
return runners, resp, nil
292+
}
293+
268294
// ListRunnerGroupRunners lists self-hosted runners that are in a specific organization group.
269295
//
270296
// GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runner-groups#list-self-hosted-runners-in-a-group-for-an-organization

github/actions_runner_groups_test.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"testing"
12+
"time"
1213

1314
"github.com/google/go-cmp/cmp"
1415
)
@@ -413,6 +414,149 @@ func TestActionsService_RemoveRepositoryAccessRunnerGroup(t *testing.T) {
413414
})
414415
}
415416

417+
func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) {
418+
t.Parallel()
419+
client, mux, _ := setup(t)
420+
421+
mux.HandleFunc("/orgs/o/actions/runner-groups/2/hosted-runners", func(w http.ResponseWriter, r *http.Request) {
422+
testMethod(t, r, "GET")
423+
testFormValues(t, r, values{"per_page": "2", "page": "2"})
424+
fmt.Fprint(w, `{
425+
"total_count": 2,
426+
"runners": [
427+
{
428+
"id": 5,
429+
"name": "My hosted ubuntu runner",
430+
"runner_group_id": 2,
431+
"platform": "linux-x64",
432+
"image_details": {
433+
"id": "ubuntu-20.04",
434+
"size_gb": 86
435+
},
436+
"machine_size_details": {
437+
"id": "4-core",
438+
"cpu_cores": 4,
439+
"memory_gb": 16,
440+
"storage_gb": 150
441+
},
442+
"status": "Ready",
443+
"maximum_runners": 10,
444+
"public_ip_enabled": true,
445+
"public_ips": [
446+
{
447+
"enabled": true,
448+
"prefix": "20.80.208.150",
449+
"length": 31
450+
}
451+
],
452+
"last_active_on": "2023-04-26T15:23:37Z"
453+
},
454+
{
455+
"id": 7,
456+
"name": "My hosted Windows runner",
457+
"runner_group_id": 2,
458+
"platform": "win-x64",
459+
"image_details": {
460+
"id": "windows-latest",
461+
"size_gb": 256
462+
},
463+
"machine_size_details": {
464+
"id": "8-core",
465+
"cpu_cores": 8,
466+
"memory_gb": 32,
467+
"storage_gb": 300
468+
},
469+
"status": "Ready",
470+
"maximum_runners": 20,
471+
"public_ip_enabled": false,
472+
"public_ips": [],
473+
"last_active_on": "2023-04-26T15:23:37Z"
474+
}
475+
]
476+
}`)
477+
})
478+
479+
opts := &ListOptions{Page: 2, PerPage: 2}
480+
ctx := t.Context()
481+
runners, _, err := client.Actions.ListRunnerGroupHostedRunners(ctx, "o", 2, opts)
482+
if err != nil {
483+
t.Errorf("Actions.ListRunnerGroupHostedRunners returned error: %v", err)
484+
}
485+
486+
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
487+
488+
want := &HostedRunners{
489+
TotalCount: 2,
490+
Runners: []*HostedRunner{
491+
{
492+
ID: Ptr(int64(5)),
493+
Name: Ptr("My hosted ubuntu runner"),
494+
RunnerGroupID: Ptr(int64(2)),
495+
Platform: Ptr("linux-x64"),
496+
ImageDetails: &HostedRunnerImageDetail{
497+
ID: Ptr("ubuntu-20.04"),
498+
SizeGB: Ptr(int64(86)),
499+
},
500+
MachineSizeDetails: &HostedRunnerMachineSpec{
501+
ID: "4-core",
502+
CPUCores: 4,
503+
MemoryGB: 16,
504+
StorageGB: 150,
505+
},
506+
Status: Ptr("Ready"),
507+
MaximumRunners: Ptr(int64(10)),
508+
PublicIPEnabled: Ptr(true),
509+
PublicIPs: []*HostedRunnerPublicIP{
510+
{
511+
Enabled: true,
512+
Prefix: "20.80.208.150",
513+
Length: 31,
514+
},
515+
},
516+
LastActiveOn: Ptr(lastActiveOn),
517+
},
518+
{
519+
ID: Ptr(int64(7)),
520+
Name: Ptr("My hosted Windows runner"),
521+
RunnerGroupID: Ptr(int64(2)),
522+
Platform: Ptr("win-x64"),
523+
ImageDetails: &HostedRunnerImageDetail{
524+
ID: Ptr("windows-latest"),
525+
SizeGB: Ptr(int64(256)),
526+
},
527+
MachineSizeDetails: &HostedRunnerMachineSpec{
528+
ID: "8-core",
529+
CPUCores: 8,
530+
MemoryGB: 32,
531+
StorageGB: 300,
532+
},
533+
Status: Ptr("Ready"),
534+
MaximumRunners: Ptr(int64(20)),
535+
PublicIPEnabled: Ptr(false),
536+
PublicIPs: []*HostedRunnerPublicIP{},
537+
LastActiveOn: Ptr(lastActiveOn),
538+
},
539+
},
540+
}
541+
if !cmp.Equal(runners, want) {
542+
t.Errorf("Actions.ListRunnerGroupHostedRunners returned %+v, want %+v", runners, want)
543+
}
544+
545+
const methodName = "ListRunnerGroupHostedRunners"
546+
testBadOptions(t, methodName, func() (err error) {
547+
_, _, err = client.Actions.ListRunnerGroupHostedRunners(ctx, "\n", 2, opts)
548+
return err
549+
})
550+
551+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
552+
got, resp, err := client.Actions.ListRunnerGroupHostedRunners(ctx, "o", 2, opts)
553+
if got != nil {
554+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
555+
}
556+
return resp, err
557+
})
558+
}
559+
416560
func TestActionsService_ListRunnerGroupRunners(t *testing.T) {
417561
t.Parallel()
418562
client, mux, _ := setup(t)

github/github-iterators.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-iterators_test.go

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)