From ec71de42cebd45b1ac9416ce2b3eb80b7efc306d Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Wed, 7 Jun 2023 12:06:54 +0200 Subject: [PATCH 1/8] Add generate-jitconfig API for self-hosted runners Signed-off-by: Magnus Kulke --- github/actions_runners.go | 58 ++++++++++++++++++++-- github/actions_runners_test.go | 89 ++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 3 deletions(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index 40c6be3a92c..d8e2b13be11 100644 --- a/github/actions_runners.go +++ b/github/actions_runners.go @@ -45,15 +45,67 @@ func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, own return rads, resp, nil } +// GenerateJITConfigRequest specifies body parameters to GenerateJITConfig. +type GenerateJITConfigRequest struct { + Name string `json:"name"` + RunnerGroupID int `json:"runner_group_id"` + Labels []string `json:"labels"` + WorkFolder string `json:"work_folder,omitempty"` +} + +// JITRunnerConfig represents encoded JIT configuration that can be used to bootstrap a self-hosted runner. +type JITRunnerConfig struct { + EncodedJITConfig *string `json:"encoded_jit_config,omitempty"` +} + +// GenerateOrganizationJITConfig 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) { + u := fmt.Sprintf("orgs/%v/actions/runners/generate-jitconfig", owner) + req, err := s.client.NewRequest("POST", u, request) + if err != nil { + return nil, nil, err + } + + jitConfig := new(JITRunnerConfig) + resp, err := s.client.Do(ctx, req, jitConfig) + if err != nil { + return nil, resp, err + } + + return jitConfig, resp, nil +} + +// GenerateJITConfig 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) { + u := fmt.Sprintf("repos/%v/%v/actions/runners/generate-jitconfig", owner, repo) + req, err := s.client.NewRequest("POST", u, request) + if err != nil { + return nil, nil, err + } + + jitConfig := new(JITRunnerConfig) + resp, err := s.client.Do(ctx, req, jitConfig) + if err != nil { + return nil, resp, err + } + + return jitConfig, resp, nil +} + +// CreateRegistrationToken creates a token that can be used to add a self-hosted runner. +// +// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository + // RegistrationToken represents a token that can be used to add a self-hosted runner to a repository. type RegistrationToken struct { Token *string `json:"token,omitempty"` ExpiresAt *Timestamp `json:"expires_at,omitempty"` } -// CreateRegistrationToken creates a token that can be used to add a self-hosted runner. -// -// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, repo string) (*RegistrationToken, *Response, error) { u := fmt.Sprintf("repos/%v/%v/actions/runners/registration-token", owner, repo) diff --git a/github/actions_runners_test.go b/github/actions_runners_test.go index 9b338641eae..d6f8e15d13e 100644 --- a/github/actions_runners_test.go +++ b/github/actions_runners_test.go @@ -7,6 +7,7 @@ package github import ( "context" + "encoding/json" "fmt" "net/http" "testing" @@ -56,6 +57,94 @@ func TestActionsService_ListRunnerApplicationDownloads(t *testing.T) { }) } +func TestActionsService_GenerateOrganizationJITConfig(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := &GenerateJITConfigRequest{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) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + if !cmp.Equal(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"encoded_jit_config":"foo"}`) + }) + + ctx := context.Background() + jitConfig, _, err := client.Actions.GenerateOrganizationJITConfig(ctx, "o", input) + if err != nil { + t.Errorf("Actions.GenerateOrganizationJITConfig returned error: %v", err) + } + + want := &JITRunnerConfig{EncodedJITConfig: String("foo")} + if !cmp.Equal(jitConfig, want) { + t.Errorf("Actions.GenerateOrganizationJITConfig returned %+v, want %+v", jitConfig, want) + } + + const methodName = "GenerateOrganizationJITConfig" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Actions.GenerateOrganizationJITConfig(ctx, "\n", input) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Actions.GenerateOrganizationJITConfig(ctx, "o", input) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestActionsService_GenerateJITConfig(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + input := &GenerateJITConfigRequest{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) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + if !cmp.Equal(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"encoded_jit_config":"foo"}`) + }) + + ctx := context.Background() + jitConfig, _, err := client.Actions.GenerateJITConfig(ctx, "o", "r", input) + if err != nil { + t.Errorf("Actions.GenerateJITConfig returned error: %v", err) + } + + want := &JITRunnerConfig{EncodedJITConfig: String("foo")} + if !cmp.Equal(jitConfig, want) { + t.Errorf("Actions.GenerateJITConfig returned %+v, want %+v", jitConfig, want) + } + + const methodName = "GenerateJITConfig" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Actions.GenerateJITConfig(ctx, "\n", "\n", input) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Actions.GenerateJITConfig(ctx, "o", "r", input) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + func TestActionsService_CreateRegistrationToken(t *testing.T) { client, mux, _, teardown := setup() defer teardown() From 2279db6a95be40127b5c120e01fa64d7063f2bb6 Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Wed, 7 Jun 2023 14:29:31 +0200 Subject: [PATCH 2/8] Update github/actions_runners.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/actions_runners.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index d8e2b13be11..34961885fc5 100644 --- a/github/actions_runners.go +++ b/github/actions_runners.go @@ -50,7 +50,7 @@ type GenerateJITConfigRequest struct { Name string `json:"name"` RunnerGroupID int `json:"runner_group_id"` Labels []string `json:"labels"` - WorkFolder string `json:"work_folder,omitempty"` + WorkFolder *string `json:"work_folder,omitempty"` } // JITRunnerConfig represents encoded JIT configuration that can be used to bootstrap a self-hosted runner. From 8cdabbaf2b79c1317e0175ad677d08b9954269f3 Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Wed, 7 Jun 2023 14:29:38 +0200 Subject: [PATCH 3/8] Update github/actions_runners.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/actions_runners.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index 34961885fc5..1844edf24ec 100644 --- a/github/actions_runners.go +++ b/github/actions_runners.go @@ -48,7 +48,7 @@ func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, own // GenerateJITConfigRequest specifies body parameters to GenerateJITConfig. type GenerateJITConfigRequest struct { Name string `json:"name"` - RunnerGroupID int `json:"runner_group_id"` + RunnerGroupID int64 `json:"runner_group_id"` Labels []string `json:"labels"` WorkFolder *string `json:"work_folder,omitempty"` } From 32e1b36639f02fdb75db06c4cb4f58685c113c11 Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Wed, 7 Jun 2023 13:12:26 +0200 Subject: [PATCH 4/8] Addressed review comments Signed-off-by: Magnus Kulke --- github/actions_runners.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index 1844edf24ec..99b613d6756 100644 --- a/github/actions_runners.go +++ b/github/actions_runners.go @@ -47,10 +47,13 @@ func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, own // GenerateJITConfigRequest specifies body parameters to GenerateJITConfig. type GenerateJITConfigRequest struct { - Name string `json:"name"` - RunnerGroupID int64 `json:"runner_group_id"` - Labels []string `json:"labels"` - WorkFolder *string `json:"work_folder,omitempty"` + Name string `json:"name"` + RunnerGroupID int64 `json:"runner_group_id"` + WorkFolder *string `json:"work_folder,omitempty"` + + // Labels represents the names of the custom labels to add to the runner. + // Minimum items: 1. Maximum items: 100. + Labels []string `json:"labels"` } // JITRunnerConfig represents encoded JIT configuration that can be used to bootstrap a self-hosted runner. @@ -96,16 +99,15 @@ func (s *ActionsService) GenerateJITConfig(ctx context.Context, owner, repo stri return jitConfig, resp, nil } -// CreateRegistrationToken creates a token that can be used to add a self-hosted runner. -// -// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository - // RegistrationToken represents a token that can be used to add a self-hosted runner to a repository. type RegistrationToken struct { Token *string `json:"token,omitempty"` ExpiresAt *Timestamp `json:"expires_at,omitempty"` } +// CreateRegistrationToken creates a token that can be used to add a self-hosted runner. +// +// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, repo string) (*RegistrationToken, *Response, error) { u := fmt.Sprintf("repos/%v/%v/actions/runners/registration-token", owner, repo) From 9162f7543eb5b51385ee568454bfce684c3c0d3f Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Wed, 7 Jun 2023 13:16:17 +0200 Subject: [PATCH 5/8] Added generated files Signed-off-by: Magnus Kulke --- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index a9aaee814ab..5f11c8c5dc4 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6310,6 +6310,14 @@ func (f *ForkEvent) GetSender() *User { return f.Sender } +// GetWorkFolder returns the WorkFolder field if it's non-nil, zero value otherwise. +func (g *GenerateJITConfigRequest) GetWorkFolder() string { + if g == nil || g.WorkFolder == nil { + return "" + } + return *g.WorkFolder +} + // GetPreviousTagName returns the PreviousTagName field if it's non-nil, zero value otherwise. func (g *GenerateNotesOptions) GetPreviousTagName() string { if g == nil || g.PreviousTagName == nil { @@ -8934,6 +8942,14 @@ func (i *IssueStats) GetTotalIssues() int { return *i.TotalIssues } +// GetEncodedJITConfig returns the EncodedJITConfig field if it's non-nil, zero value otherwise. +func (j *JITRunnerConfig) GetEncodedJITConfig() string { + if j == nil || j.EncodedJITConfig == nil { + return "" + } + return *j.EncodedJITConfig +} + // GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise. func (j *Jobs) GetTotalCount() int { if j == nil || j.TotalCount == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index a29baa0f0c4..ec0c6d88ac5 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -7363,6 +7363,16 @@ func TestForkEvent_GetSender(tt *testing.T) { f.GetSender() } +func TestGenerateJITConfigRequest_GetWorkFolder(tt *testing.T) { + var zeroValue string + g := &GenerateJITConfigRequest{WorkFolder: &zeroValue} + g.GetWorkFolder() + g = &GenerateJITConfigRequest{} + g.GetWorkFolder() + g = nil + g.GetWorkFolder() +} + func TestGenerateNotesOptions_GetPreviousTagName(tt *testing.T) { var zeroValue string g := &GenerateNotesOptions{PreviousTagName: &zeroValue} @@ -10457,6 +10467,16 @@ func TestIssueStats_GetTotalIssues(tt *testing.T) { i.GetTotalIssues() } +func TestJITRunnerConfig_GetEncodedJITConfig(tt *testing.T) { + var zeroValue string + j := &JITRunnerConfig{EncodedJITConfig: &zeroValue} + j.GetEncodedJITConfig() + j = &JITRunnerConfig{} + j.GetEncodedJITConfig() + j = nil + j.GetEncodedJITConfig() +} + func TestJobs_GetTotalCount(tt *testing.T) { var zeroValue int j := &Jobs{TotalCount: &zeroValue} From 1e69ccfbec4225f940e1acb78d2e5914283dcfd1 Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Thu, 8 Jun 2023 08:18:20 +0200 Subject: [PATCH 6/8] Addressed review comments Signed-off-by: Magnus Kulke --- github/actions_runners.go | 12 ++++++------ github/actions_runners_test.go | 36 +++++++++++++++++----------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index 99b613d6756..4d0f24cf39b 100644 --- a/github/actions_runners.go +++ b/github/actions_runners.go @@ -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. +type GenerateRepoJITConfigRequest struct { Name string `json:"name"` RunnerGroupID int64 `json:"runner_group_id"` WorkFolder *string `json:"work_folder,omitempty"` @@ -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 { @@ -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 { diff --git a/github/actions_runners_test.go b/github/actions_runners_test.go index d6f8e15d13e..38d9739658c 100644 --- a/github/actions_runners_test.go +++ b/github/actions_runners_test.go @@ -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") @@ -76,24 +76,24 @@ 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) } @@ -101,14 +101,14 @@ func TestActionsService_GenerateOrganizationJITConfig(t *testing.T) { }) } -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") @@ -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) } From 9ed90085cc7a346cfe1ee391a31236e363c74802 Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Thu, 8 Jun 2023 08:18:41 +0200 Subject: [PATCH 7/8] Codegen Signed-off-by: Magnus Kulke --- github/github-accessors.go | 16 ++++++++-------- github/github-accessors_test.go | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 5f11c8c5dc4..990b4560df7 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6310,14 +6310,6 @@ func (f *ForkEvent) GetSender() *User { return f.Sender } -// GetWorkFolder returns the WorkFolder field if it's non-nil, zero value otherwise. -func (g *GenerateJITConfigRequest) GetWorkFolder() string { - if g == nil || g.WorkFolder == nil { - return "" - } - return *g.WorkFolder -} - // GetPreviousTagName returns the PreviousTagName field if it's non-nil, zero value otherwise. func (g *GenerateNotesOptions) GetPreviousTagName() string { if g == nil || g.PreviousTagName == nil { @@ -6334,6 +6326,14 @@ func (g *GenerateNotesOptions) GetTargetCommitish() string { return *g.TargetCommitish } +// GetWorkFolder returns the WorkFolder field if it's non-nil, zero value otherwise. +func (g *GenerateRepoJITConfigRequest) GetWorkFolder() string { + if g == nil || g.WorkFolder == nil { + return "" + } + return *g.WorkFolder +} + // GetInclude returns the Include field if it's non-nil, zero value otherwise. func (g *GetAuditLogOptions) GetInclude() string { if g == nil || g.Include == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index ec0c6d88ac5..3b40f3e2393 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -7363,16 +7363,6 @@ func TestForkEvent_GetSender(tt *testing.T) { f.GetSender() } -func TestGenerateJITConfigRequest_GetWorkFolder(tt *testing.T) { - var zeroValue string - g := &GenerateJITConfigRequest{WorkFolder: &zeroValue} - g.GetWorkFolder() - g = &GenerateJITConfigRequest{} - g.GetWorkFolder() - g = nil - g.GetWorkFolder() -} - func TestGenerateNotesOptions_GetPreviousTagName(tt *testing.T) { var zeroValue string g := &GenerateNotesOptions{PreviousTagName: &zeroValue} @@ -7393,6 +7383,16 @@ func TestGenerateNotesOptions_GetTargetCommitish(tt *testing.T) { g.GetTargetCommitish() } +func TestGenerateRepoJITConfigRequest_GetWorkFolder(tt *testing.T) { + var zeroValue string + g := &GenerateRepoJITConfigRequest{WorkFolder: &zeroValue} + g.GetWorkFolder() + g = &GenerateRepoJITConfigRequest{} + g.GetWorkFolder() + g = nil + g.GetWorkFolder() +} + func TestGetAuditLogOptions_GetInclude(tt *testing.T) { var zeroValue string g := &GetAuditLogOptions{Include: &zeroValue} From 82526e34ac2a25aefffad1e46fce8190beb98ffa Mon Sep 17 00:00:00 2001 From: Magnus Kulke Date: Thu, 8 Jun 2023 15:55:22 +0200 Subject: [PATCH 8/8] Renamed config struct Signed-off-by: Magnus Kulke --- github/actions_runners.go | 8 ++++---- github/actions_runners_test.go | 8 ++++---- github/github-accessors.go | 16 ++++++++-------- github/github-accessors_test.go | 20 ++++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/github/actions_runners.go b/github/actions_runners.go index 4d0f24cf39b..3990a5a90f7 100644 --- a/github/actions_runners.go +++ b/github/actions_runners.go @@ -45,8 +45,8 @@ func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, own return rads, resp, nil } -// GenerateRepoJITConfigRequest specifies body parameters to GenerateRepoJITConfig. -type GenerateRepoJITConfigRequest struct { +// GenerateJITConfigRequest specifies body parameters to GenerateRepoJITConfig. +type GenerateJITConfigRequest struct { Name string `json:"name"` RunnerGroupID int64 `json:"runner_group_id"` WorkFolder *string `json:"work_folder,omitempty"` @@ -64,7 +64,7 @@ type JITRunnerConfig struct { // 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) GenerateOrgJITConfig(ctx context.Context, owner string, request *GenerateRepoJITConfigRequest) (*JITRunnerConfig, *Response, error) { +func (s *ActionsService) GenerateOrgJITConfig(ctx context.Context, owner string, request *GenerateJITConfigRequest) (*JITRunnerConfig, *Response, error) { u := fmt.Sprintf("orgs/%v/actions/runners/generate-jitconfig", owner) req, err := s.client.NewRequest("POST", u, request) if err != nil { @@ -83,7 +83,7 @@ func (s *ActionsService) GenerateOrgJITConfig(ctx context.Context, owner string, // 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) GenerateRepoJITConfig(ctx context.Context, owner, repo string, request *GenerateRepoJITConfigRequest) (*JITRunnerConfig, *Response, error) { +func (s *ActionsService) GenerateRepoJITConfig(ctx context.Context, owner, repo string, request *GenerateJITConfigRequest) (*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 { diff --git a/github/actions_runners_test.go b/github/actions_runners_test.go index 38d9739658c..8063152f93a 100644 --- a/github/actions_runners_test.go +++ b/github/actions_runners_test.go @@ -61,10 +61,10 @@ func TestActionsService_GenerateOrgJITConfig(t *testing.T) { client, mux, _, teardown := setup() defer teardown() - input := &GenerateRepoJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}} + input := &GenerateJITConfigRequest{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(GenerateRepoJITConfigRequest) + v := new(GenerateJITConfigRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") @@ -105,10 +105,10 @@ func TestActionsService_GenerateRepoJITConfig(t *testing.T) { client, mux, _, teardown := setup() defer teardown() - input := &GenerateRepoJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}} + input := &GenerateJITConfigRequest{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(GenerateRepoJITConfigRequest) + v := new(GenerateJITConfigRequest) json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "POST") diff --git a/github/github-accessors.go b/github/github-accessors.go index 990b4560df7..5f11c8c5dc4 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6310,6 +6310,14 @@ func (f *ForkEvent) GetSender() *User { return f.Sender } +// GetWorkFolder returns the WorkFolder field if it's non-nil, zero value otherwise. +func (g *GenerateJITConfigRequest) GetWorkFolder() string { + if g == nil || g.WorkFolder == nil { + return "" + } + return *g.WorkFolder +} + // GetPreviousTagName returns the PreviousTagName field if it's non-nil, zero value otherwise. func (g *GenerateNotesOptions) GetPreviousTagName() string { if g == nil || g.PreviousTagName == nil { @@ -6326,14 +6334,6 @@ func (g *GenerateNotesOptions) GetTargetCommitish() string { return *g.TargetCommitish } -// GetWorkFolder returns the WorkFolder field if it's non-nil, zero value otherwise. -func (g *GenerateRepoJITConfigRequest) GetWorkFolder() string { - if g == nil || g.WorkFolder == nil { - return "" - } - return *g.WorkFolder -} - // GetInclude returns the Include field if it's non-nil, zero value otherwise. func (g *GetAuditLogOptions) GetInclude() string { if g == nil || g.Include == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 3b40f3e2393..ec0c6d88ac5 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -7363,6 +7363,16 @@ func TestForkEvent_GetSender(tt *testing.T) { f.GetSender() } +func TestGenerateJITConfigRequest_GetWorkFolder(tt *testing.T) { + var zeroValue string + g := &GenerateJITConfigRequest{WorkFolder: &zeroValue} + g.GetWorkFolder() + g = &GenerateJITConfigRequest{} + g.GetWorkFolder() + g = nil + g.GetWorkFolder() +} + func TestGenerateNotesOptions_GetPreviousTagName(tt *testing.T) { var zeroValue string g := &GenerateNotesOptions{PreviousTagName: &zeroValue} @@ -7383,16 +7393,6 @@ func TestGenerateNotesOptions_GetTargetCommitish(tt *testing.T) { g.GetTargetCommitish() } -func TestGenerateRepoJITConfigRequest_GetWorkFolder(tt *testing.T) { - var zeroValue string - g := &GenerateRepoJITConfigRequest{WorkFolder: &zeroValue} - g.GetWorkFolder() - g = &GenerateRepoJITConfigRequest{} - g.GetWorkFolder() - g = nil - g.GetWorkFolder() -} - func TestGetAuditLogOptions_GetInclude(tt *testing.T) { var zeroValue string g := &GetAuditLogOptions{Include: &zeroValue}