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

Add generate-jitconfig API for self-hosted runners #2801

Merged
merged 8 commits into from
Jun 19, 2023
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
12 changes: 6 additions & 6 deletions github/actions_runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, own
return rads, resp, nil
}

// GenerateJITConfigRequest specifies body parameters to GenerateJITConfig.
type GenerateJITConfigRequest struct {
// GenerateRepoJITConfigRequest specifies body parameters to GenerateRepoJITConfig.
mkulke marked this conversation as resolved.
Show resolved Hide resolved
type GenerateRepoJITConfigRequest struct {
Name string `json:"name"`
RunnerGroupID int64 `json:"runner_group_id"`
WorkFolder *string `json:"work_folder,omitempty"`
Expand All @@ -61,10 +61,10 @@ type JITRunnerConfig struct {
EncodedJITConfig *string `json:"encoded_jit_config,omitempty"`
}

// GenerateOrganizationJITConfig generate a just-in-time configuration for an organization.
// GenerateOrgJITConfig generate a just-in-time configuration for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-configuration-for-a-just-in-time-runner-for-an-organization
func (s *ActionsService) GenerateOrganizationJITConfig(ctx context.Context, owner string, request *GenerateJITConfigRequest) (*JITRunnerConfig, *Response, error) {
func (s *ActionsService) GenerateOrgJITConfig(ctx context.Context, owner string, request *GenerateRepoJITConfigRequest) (*JITRunnerConfig, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/generate-jitconfig", owner)
req, err := s.client.NewRequest("POST", u, request)
if err != nil {
Expand All @@ -80,10 +80,10 @@ func (s *ActionsService) GenerateOrganizationJITConfig(ctx context.Context, owne
return jitConfig, resp, nil
}

// GenerateJITConfig generates a just-in-time configuration for a repository.
// GenerateRepoJITConfig generates a just-in-time configuration for a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-configuration-for-a-just-in-time-runner-for-a-repository
func (s *ActionsService) GenerateJITConfig(ctx context.Context, owner, repo string, request *GenerateJITConfigRequest) (*JITRunnerConfig, *Response, error) {
func (s *ActionsService) GenerateRepoJITConfig(ctx context.Context, owner, repo string, request *GenerateRepoJITConfigRequest) (*JITRunnerConfig, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners/generate-jitconfig", owner, repo)
req, err := s.client.NewRequest("POST", u, request)
if err != nil {
Expand Down
36 changes: 18 additions & 18 deletions github/actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ func TestActionsService_ListRunnerApplicationDownloads(t *testing.T) {
})
}

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

input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}
input := &GenerateRepoJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}

mux.HandleFunc("/orgs/o/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
v := new(GenerateJITConfigRequest)
v := new(GenerateRepoJITConfigRequest)
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
Expand All @@ -76,39 +76,39 @@ func TestActionsService_GenerateOrganizationJITConfig(t *testing.T) {
})

ctx := context.Background()
jitConfig, _, err := client.Actions.GenerateOrganizationJITConfig(ctx, "o", input)
jitConfig, _, err := client.Actions.GenerateOrgJITConfig(ctx, "o", input)
if err != nil {
t.Errorf("Actions.GenerateOrganizationJITConfig returned error: %v", err)
t.Errorf("Actions.GenerateOrgJITConfig returned error: %v", err)
}

want := &JITRunnerConfig{EncodedJITConfig: String("foo")}
if !cmp.Equal(jitConfig, want) {
t.Errorf("Actions.GenerateOrganizationJITConfig returned %+v, want %+v", jitConfig, want)
t.Errorf("Actions.GenerateOrgJITConfig returned %+v, want %+v", jitConfig, want)
}

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

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

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

input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}
input := &GenerateRepoJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}

mux.HandleFunc("/repos/o/r/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
v := new(GenerateJITConfigRequest)
v := new(GenerateRepoJITConfigRequest)
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
Expand All @@ -120,24 +120,24 @@ func TestActionsService_GenerateJITConfig(t *testing.T) {
})

ctx := context.Background()
jitConfig, _, err := client.Actions.GenerateJITConfig(ctx, "o", "r", input)
jitConfig, _, err := client.Actions.GenerateRepoJITConfig(ctx, "o", "r", input)
if err != nil {
t.Errorf("Actions.GenerateJITConfig returned error: %v", err)
t.Errorf("Actions.GenerateRepoJITConfig returned error: %v", err)
}

want := &JITRunnerConfig{EncodedJITConfig: String("foo")}
if !cmp.Equal(jitConfig, want) {
t.Errorf("Actions.GenerateJITConfig returned %+v, want %+v", jitConfig, want)
t.Errorf("Actions.GenerateRepoJITConfig returned %+v, want %+v", jitConfig, want)
}

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

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GenerateJITConfig(ctx, "o", "r", input)
got, resp, err := client.Actions.GenerateRepoJITConfig(ctx, "o", "r", input)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down
16 changes: 8 additions & 8 deletions github/github-accessors.go

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

20 changes: 10 additions & 10 deletions github/github-accessors_test.go

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