From 7c6f50dd9976ee953d44d742c33a28f7dc2b1ca8 Mon Sep 17 00:00:00 2001 From: Matt Simons Date: Tue, 11 Jun 2024 10:57:44 +0100 Subject: [PATCH] Add support for Enterprise GetRunner --- github/enterprise_actions_runners.go | 21 ++++++++++++ github/enterprise_actions_runners_test.go | 40 +++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/github/enterprise_actions_runners.go b/github/enterprise_actions_runners.go index a5364815324..fa345aea8a9 100644 --- a/github/enterprise_actions_runners.go +++ b/github/enterprise_actions_runners.go @@ -101,6 +101,27 @@ func (s *EnterpriseService) ListRunners(ctx context.Context, enterprise string, return runners, resp, nil } +// GetRunner gets a specific self-hosted runner configured in an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#get-a-self-hosted-runner-for-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/actions/runners/{runner_id} +func (s *EnterpriseService) GetRunner(ctx context.Context, enterprise string, runnerID int64) (*Runner, *Response, error) { + u := fmt.Sprintf("enterprises/%v/actions/runners/%v", enterprise, runnerID) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + runner := new(Runner) + resp, err := s.client.Do(ctx, req, runner) + if err != nil { + return nil, resp, err + } + + return runner, resp, nil +} + // RemoveRunner forces the removal of a self-hosted runner from an enterprise using the runner id. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-an-enterprise diff --git a/github/enterprise_actions_runners_test.go b/github/enterprise_actions_runners_test.go index 3bc3c737b89..d5efc6f7f03 100644 --- a/github/enterprise_actions_runners_test.go +++ b/github/enterprise_actions_runners_test.go @@ -145,6 +145,46 @@ func TestEnterpriseService_ListRunners(t *testing.T) { }) } +func TestEnterpriseService_GetRunner(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/enterprises/e/actions/runners/23", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"id":23,"name":"MBP","os":"macos","status":"online"}`) + }) + + ctx := context.Background() + runner, _, err := client.Enterprise.GetRunner(ctx, "e", 23) + if err != nil { + t.Errorf("Enterprise.GetRunner returned error: %v", err) + } + + want := &Runner{ + ID: Int64(23), + Name: String("MBP"), + OS: String("macos"), + Status: String("online"), + } + if !cmp.Equal(runner, want) { + t.Errorf("Enterprise.GetRunner returned %+v, want %+v", runner, want) + } + + const methodName = "GetRunner" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Enterprise.GetRunner(ctx, "\n", 23) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.GetRunner(ctx, "e", 23) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + func TestEnterpriseService_RemoveRunner(t *testing.T) { client, mux, _, teardown := setup() defer teardown()