Skip to content
New issue

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

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

Already on GitHub? # to your account

Add support for Enterprise GetRunner #3185

Merged
merged 1 commit into from
Jul 2, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions github/enterprise_actions_runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions github/enterprise_actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading