Skip to content

Commit 90a1849

Browse files
authored
feat!: Refactor dependabot secrets to pass request by value (#4348)
BREAKING CHANGE: `DependabotService` methods involving secrets have new params and return values.
1 parent b44ebf5 commit 90a1849

9 files changed

Lines changed: 448 additions & 549 deletions

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@ linters:
409409
- CreateTag.Object # TODO: Git
410410
- CreateTag.Tag # TODO: Git
411411
- CreateTag.Type # TODO: Git
412-
- DependabotEncryptedSecret.SelectedRepositoryIDs # TODO: Dependabot
413-
- DependabotEncryptedSecret.Visibility # TODO: Dependabot
414412
- DismissalRestrictionsRequest.Apps # TODO: Repositories
415413
- DismissalRestrictionsRequest.Teams # TODO: Repositories
416414
- DismissalRestrictionsRequest.Users # TODO: Repositories

github/actions_secrets.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ type EncryptedSecret struct {
296296
SelectedRepositoryIDs SelectedRepoIDs `json:"selected_repository_ids,omitempty"`
297297
}
298298

299-
// OrgSecretRequest represents a request to create or update a secret for an
299+
// SecretOrgRequest represents a request to create or update a secret for an
300300
// organization.
301301
//
302302
// The value of EncryptedValue must be your secret, encrypted with
303303
// LibSodium (see documentation here: https://libsodium.gitbook.io/doc/bindings_for_other_languages)
304304
// using the public key retrieved using the GetPublicKey method.
305-
type OrgSecretRequest struct {
305+
type SecretOrgRequest struct {
306306
KeyID string `json:"key_id"`
307307
EncryptedValue string `json:"encrypted_value"`
308308
Visibility string `json:"visibility"`
@@ -341,7 +341,7 @@ func (s *ActionsService) CreateOrUpdateRepoSecret(ctx context.Context, owner, re
341341
// GitHub API docs: https://docs.github.com/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
342342
//
343343
//meta:operation PUT /orgs/{org}/actions/secrets/{secret_name}
344-
func (s *ActionsService) CreateOrUpdateOrgSecret(ctx context.Context, org, name string, body OrgSecretRequest) (*Response, error) {
344+
func (s *ActionsService) CreateOrUpdateOrgSecret(ctx context.Context, org, name string, body SecretOrgRequest) (*Response, error) {
345345
u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, name)
346346

347347
req, err := s.client.NewRequest(ctx, "PUT", u, body)

github/actions_secrets_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func TestActionsService_CreateOrUpdateOrgSecret(t *testing.T) {
472472
t.Parallel()
473473
client, mux, _ := setup(t)
474474

475-
input := OrgSecretRequest{
475+
input := SecretOrgRequest{
476476
KeyID: "1234",
477477
EncryptedValue: "QIv=",
478478
Visibility: "selected",
@@ -482,7 +482,7 @@ func TestActionsService_CreateOrUpdateOrgSecret(t *testing.T) {
482482
mux.HandleFunc("/orgs/o/actions/secrets/NAME", func(w http.ResponseWriter, r *http.Request) {
483483
testMethod(t, r, "PUT")
484484
testHeader(t, r, "Content-Type", "application/json")
485-
want := OrgSecretRequest{
485+
want := SecretOrgRequest{
486486
KeyID: "1234",
487487
EncryptedValue: "QIv=",
488488
Visibility: "selected",

github/actions_variables.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ import (
1111
"fmt"
1212
)
1313

14-
// OrgActionsVariableCreateRequest represents a request to create an
14+
// ActionsCreateOrgVariableRequest represents a request to create an
1515
// organization variable.
16-
type OrgActionsVariableCreateRequest struct {
16+
type ActionsCreateOrgVariableRequest struct {
1717
Name string `json:"name"`
1818
Value string `json:"value"`
1919
Visibility string `json:"visibility"`
2020
SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitzero"`
2121
}
2222

23-
// OrgActionsVariableUpdateRequest represents a request to update an
23+
// ActionsUpdateOrgVariableRequest represents a request to update an
2424
// organization variable.
25-
type OrgActionsVariableUpdateRequest struct {
25+
type ActionsUpdateOrgVariableRequest struct {
2626
Name *string `json:"name,omitempty"`
2727
Value *string `json:"value,omitempty"`
2828
Visibility *string `json:"visibility,omitempty"`
2929
SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitzero"`
3030
}
3131

32-
// ActionsVariableCreateRequest represents a request to create a variable
32+
// ActionsCreateVariableRequest represents a request to create a variable
3333
// for a repository or repository environment variable.
34-
type ActionsVariableCreateRequest struct {
34+
type ActionsCreateVariableRequest struct {
3535
Name string `json:"name"`
3636
Value string `json:"value"`
3737
}
3838

39-
// ActionsVariableUpdateRequest represents a request to update a variable
39+
// ActionsUpdateVariableRequest represents a request to update a variable
4040
// for a repository or repository environment variable.
41-
type ActionsVariableUpdateRequest struct {
41+
type ActionsUpdateVariableRequest struct {
4242
Name *string `json:"name,omitempty"`
4343
Value *string `json:"value,omitempty"`
4444
}
@@ -236,7 +236,7 @@ func (s *ActionsService) GetEnvVariable(ctx context.Context, owner, repo, env, v
236236
// GitHub API docs: https://docs.github.com/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable
237237
//
238238
//meta:operation POST /repos/{owner}/{repo}/actions/variables
239-
func (s *ActionsService) CreateRepoVariable(ctx context.Context, owner, repo string, body ActionsVariableCreateRequest) (*Response, error) {
239+
func (s *ActionsService) CreateRepoVariable(ctx context.Context, owner, repo string, body ActionsCreateVariableRequest) (*Response, error) {
240240
u := fmt.Sprintf("repos/%v/%v/actions/variables", owner, repo)
241241

242242
req, err := s.client.NewRequest(ctx, "POST", u, body)
@@ -252,7 +252,7 @@ func (s *ActionsService) CreateRepoVariable(ctx context.Context, owner, repo str
252252
// GitHub API docs: https://docs.github.com/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable
253253
//
254254
//meta:operation POST /orgs/{org}/actions/variables
255-
func (s *ActionsService) CreateOrgVariable(ctx context.Context, org string, body OrgActionsVariableCreateRequest) (*Response, error) {
255+
func (s *ActionsService) CreateOrgVariable(ctx context.Context, org string, body ActionsCreateOrgVariableRequest) (*Response, error) {
256256
u := fmt.Sprintf("orgs/%v/actions/variables", org)
257257

258258
req, err := s.client.NewRequest(ctx, "POST", u, body)
@@ -268,7 +268,7 @@ func (s *ActionsService) CreateOrgVariable(ctx context.Context, org string, body
268268
// GitHub API docs: https://docs.github.com/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable
269269
//
270270
//meta:operation POST /repos/{owner}/{repo}/environments/{environment_name}/variables
271-
func (s *ActionsService) CreateEnvVariable(ctx context.Context, owner, repo, env string, body ActionsVariableCreateRequest) (*Response, error) {
271+
func (s *ActionsService) CreateEnvVariable(ctx context.Context, owner, repo, env string, body ActionsCreateVariableRequest) (*Response, error) {
272272
u := fmt.Sprintf("repos/%v/%v/environments/%v/variables", owner, repo, env)
273273

274274
req, err := s.client.NewRequest(ctx, "POST", u, body)
@@ -283,7 +283,7 @@ func (s *ActionsService) CreateEnvVariable(ctx context.Context, owner, repo, env
283283
// GitHub API docs: https://docs.github.com/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable
284284
//
285285
//meta:operation PATCH /repos/{owner}/{repo}/actions/variables/{name}
286-
func (s *ActionsService) UpdateRepoVariable(ctx context.Context, owner, repo, name string, body ActionsVariableUpdateRequest) (*Response, error) {
286+
func (s *ActionsService) UpdateRepoVariable(ctx context.Context, owner, repo, name string, body ActionsUpdateVariableRequest) (*Response, error) {
287287
u := fmt.Sprintf("repos/%v/%v/actions/variables/%v", owner, repo, name)
288288

289289
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
@@ -299,7 +299,7 @@ func (s *ActionsService) UpdateRepoVariable(ctx context.Context, owner, repo, na
299299
// GitHub API docs: https://docs.github.com/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable
300300
//
301301
//meta:operation PATCH /orgs/{org}/actions/variables/{name}
302-
func (s *ActionsService) UpdateOrgVariable(ctx context.Context, org, name string, body OrgActionsVariableUpdateRequest) (*Response, error) {
302+
func (s *ActionsService) UpdateOrgVariable(ctx context.Context, org, name string, body ActionsUpdateOrgVariableRequest) (*Response, error) {
303303
u := fmt.Sprintf("orgs/%v/actions/variables/%v", org, name)
304304

305305
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
@@ -315,7 +315,7 @@ func (s *ActionsService) UpdateOrgVariable(ctx context.Context, org, name string
315315
// GitHub API docs: https://docs.github.com/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable
316316
//
317317
//meta:operation PATCH /repos/{owner}/{repo}/environments/{environment_name}/variables/{name}
318-
func (s *ActionsService) UpdateEnvVariable(ctx context.Context, owner, repo, env, name string, body ActionsVariableUpdateRequest) (*Response, error) {
318+
func (s *ActionsService) UpdateEnvVariable(ctx context.Context, owner, repo, env, name string, body ActionsUpdateVariableRequest) (*Response, error) {
319319
u := fmt.Sprintf("repos/%v/%v/environments/%v/variables/%v", owner, repo, env, name)
320320

321321
req, err := s.client.NewRequest(ctx, "PATCH", u, body)

github/actions_variables_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestActionsService_CreateRepoVariable(t *testing.T) {
143143
t.Parallel()
144144
client, mux, _ := setup(t)
145145

146-
input := ActionsVariableCreateRequest{
146+
input := ActionsCreateVariableRequest{
147147
Name: "NAME",
148148
Value: "VALUE",
149149
}
@@ -177,7 +177,7 @@ func TestActionsService_UpdateRepoVariable(t *testing.T) {
177177
client, mux, _ := setup(t)
178178

179179
name := "NAME"
180-
input := ActionsVariableUpdateRequest{
180+
input := ActionsUpdateVariableRequest{
181181
Name: &name,
182182
Value: Ptr("VALUE"),
183183
}
@@ -321,7 +321,7 @@ func TestActionsService_CreateOrgVariable(t *testing.T) {
321321
t.Parallel()
322322
client, mux, _ := setup(t)
323323

324-
input := OrgActionsVariableCreateRequest{
324+
input := ActionsCreateOrgVariableRequest{
325325
Name: "NAME",
326326
Value: "VALUE",
327327
Visibility: "selected",
@@ -357,7 +357,7 @@ func TestActionsService_UpdateOrgVariable(t *testing.T) {
357357
client, mux, _ := setup(t)
358358

359359
name := "NAME"
360-
input := OrgActionsVariableUpdateRequest{
360+
input := ActionsUpdateOrgVariableRequest{
361361
Name: &name,
362362
Value: Ptr("VALUE"),
363363
Visibility: Ptr("selected"),
@@ -642,7 +642,7 @@ func TestActionsService_CreateEnvVariable(t *testing.T) {
642642
t.Parallel()
643643
client, mux, _ := setup(t)
644644

645-
input := ActionsVariableCreateRequest{
645+
input := ActionsCreateVariableRequest{
646646
Name: "NAME",
647647
Value: "VAR",
648648
}
@@ -676,7 +676,7 @@ func TestActionsService_UpdateEnvVariable(t *testing.T) {
676676
client, mux, _ := setup(t)
677677

678678
name := "NAME"
679-
input := ActionsVariableUpdateRequest{
679+
input := ActionsUpdateVariableRequest{
680680
Name: &name,
681681
Value: Ptr("VAR"),
682682
}

0 commit comments

Comments
 (0)