Skip to content

Commit ce1f6b9

Browse files
authored
Change DependabotSecretsSelectedRepoIDs to []string (#2401)
Fixes #2400.
1 parent 388289c commit ce1f6b9

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

‎github/actions_secrets.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (s *ActionsService) GetEnvSecret(ctx context.Context, repoID int, env, secr
186186
return s.getSecret(ctx, url)
187187
}
188188

189-
// SelectedRepoIDs are the repository IDs that have access to the secret.
189+
// SelectedRepoIDs are the repository IDs that have access to the actions secrets.
190190
type SelectedRepoIDs []int64
191191

192192
// EncryptedSecret represents a secret that is encrypted using a public key.

‎github/dependabot_secrets.go‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,20 @@ func (s *DependabotService) GetOrgSecret(ctx context.Context, org, name string)
110110
return s.getSecret(ctx, url)
111111
}
112112

113-
func (s *DependabotService) putSecret(ctx context.Context, url string, eSecret *EncryptedSecret) (*Response, error) {
113+
// DependabotEncryptedSecret represents a secret that is encrypted using a public key for Dependabot.
114+
//
115+
// The value of EncryptedValue must be your secret, encrypted with
116+
// LibSodium (see documentation here: https://libsodium.gitbook.io/doc/bindings_for_other_languages)
117+
// using the public key retrieved using the GetPublicKey method.
118+
type DependabotEncryptedSecret struct {
119+
Name string `json:"-"`
120+
KeyID string `json:"key_id"`
121+
EncryptedValue string `json:"encrypted_value"`
122+
Visibility string `json:"visibility,omitempty"`
123+
SelectedRepositoryIDs DependabotSecretsSelectedRepoIDs `json:"selected_repository_ids,omitempty"`
124+
}
125+
126+
func (s *DependabotService) putSecret(ctx context.Context, url string, eSecret *DependabotEncryptedSecret) (*Response, error) {
114127
req, err := s.client.NewRequest("PUT", url, eSecret)
115128
if err != nil {
116129
return nil, err
@@ -122,15 +135,15 @@ func (s *DependabotService) putSecret(ctx context.Context, url string, eSecret *
122135
// CreateOrUpdateRepoSecret creates or updates a repository Dependabot secret with an encrypted value.
123136
//
124137
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#create-or-update-a-repository-secret
125-
func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *EncryptedSecret) (*Response, error) {
138+
func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *DependabotEncryptedSecret) (*Response, error) {
126139
url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, eSecret.Name)
127140
return s.putSecret(ctx, url, eSecret)
128141
}
129142

130143
// CreateOrUpdateOrgSecret creates or updates an organization Dependabot secret with an encrypted value.
131144
//
132145
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#create-or-update-an-organization-secret
133-
func (s *DependabotService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *EncryptedSecret) (*Response, error) {
146+
func (s *DependabotService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *DependabotEncryptedSecret) (*Response, error) {
134147
url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, eSecret.Name)
135148
return s.putSecret(ctx, url, eSecret)
136149
}
@@ -184,13 +197,16 @@ func (s *DependabotService) ListSelectedReposForOrgSecret(ctx context.Context, o
184197
return result, resp, nil
185198
}
186199

200+
// DependabotSecretsSelectedRepoIDs are the repository IDs that have access to the dependabot secrets.
201+
type DependabotSecretsSelectedRepoIDs []string
202+
187203
// SetSelectedReposForOrgSecret sets the repositories that have access to a Dependabot secret.
188204
//
189205
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#set-selected-repositories-for-an-organization-secret
190-
func (s *DependabotService) SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids SelectedRepoIDs) (*Response, error) {
206+
func (s *DependabotService) SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids DependabotSecretsSelectedRepoIDs) (*Response, error) {
191207
url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v/repositories", org, name)
192208
type repoIDs struct {
193-
SelectedIDs SelectedRepoIDs `json:"selected_repository_ids"`
209+
SelectedIDs DependabotSecretsSelectedRepoIDs `json:"selected_repository_ids"`
194210
}
195211

196212
req, err := s.client.NewRequest("PUT", url, repoIDs{SelectedIDs: ids})

‎github/dependabot_secrets_test.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestDependabotService_CreateOrUpdateRepoSecret(t *testing.T) {
178178
w.WriteHeader(http.StatusCreated)
179179
})
180180

181-
input := &EncryptedSecret{
181+
input := &DependabotEncryptedSecret{
182182
Name: "NAME",
183183
EncryptedValue: "QIv=",
184184
KeyID: "1234",
@@ -352,16 +352,16 @@ func TestDependabotService_CreateOrUpdateOrgSecret(t *testing.T) {
352352
mux.HandleFunc("/orgs/o/dependabot/secrets/NAME", func(w http.ResponseWriter, r *http.Request) {
353353
testMethod(t, r, "PUT")
354354
testHeader(t, r, "Content-Type", "application/json")
355-
testBody(t, r, `{"key_id":"1234","encrypted_value":"QIv=","visibility":"selected","selected_repository_ids":[1296269,1269280]}`+"\n")
355+
testBody(t, r, `{"key_id":"1234","encrypted_value":"QIv=","visibility":"selected","selected_repository_ids":["1296269","1269280"]}`+"\n")
356356
w.WriteHeader(http.StatusCreated)
357357
})
358358

359-
input := &EncryptedSecret{
359+
input := &DependabotEncryptedSecret{
360360
Name: "NAME",
361361
EncryptedValue: "QIv=",
362362
KeyID: "1234",
363363
Visibility: "selected",
364-
SelectedRepositoryIDs: SelectedRepoIDs{1296269, 1269280},
364+
SelectedRepositoryIDs: DependabotSecretsSelectedRepoIDs{"1296269", "1269280"},
365365
}
366366
ctx := context.Background()
367367
_, err := client.Dependabot.CreateOrUpdateOrgSecret(ctx, "o", input)
@@ -428,23 +428,23 @@ func TestDependabotService_SetSelectedReposForOrgSecret(t *testing.T) {
428428
mux.HandleFunc("/orgs/o/dependabot/secrets/NAME/repositories", func(w http.ResponseWriter, r *http.Request) {
429429
testMethod(t, r, "PUT")
430430
testHeader(t, r, "Content-Type", "application/json")
431-
testBody(t, r, `{"selected_repository_ids":[64780797]}`+"\n")
431+
testBody(t, r, `{"selected_repository_ids":["64780797"]}`+"\n")
432432
})
433433

434434
ctx := context.Background()
435-
_, err := client.Dependabot.SetSelectedReposForOrgSecret(ctx, "o", "NAME", SelectedRepoIDs{64780797})
435+
_, err := client.Dependabot.SetSelectedReposForOrgSecret(ctx, "o", "NAME", DependabotSecretsSelectedRepoIDs{"64780797"})
436436
if err != nil {
437437
t.Errorf("Dependabot.SetSelectedReposForOrgSecret returned error: %v", err)
438438
}
439439

440440
const methodName = "SetSelectedReposForOrgSecret"
441441
testBadOptions(t, methodName, func() (err error) {
442-
_, err = client.Dependabot.SetSelectedReposForOrgSecret(ctx, "\n", "\n", SelectedRepoIDs{64780797})
442+
_, err = client.Dependabot.SetSelectedReposForOrgSecret(ctx, "\n", "\n", DependabotSecretsSelectedRepoIDs{"64780797"})
443443
return err
444444
})
445445

446446
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
447-
return client.Dependabot.SetSelectedReposForOrgSecret(ctx, "o", "NAME", SelectedRepoIDs{64780797})
447+
return client.Dependabot.SetSelectedReposForOrgSecret(ctx, "o", "NAME", DependabotSecretsSelectedRepoIDs{"64780797"})
448448
})
449449
}
450450

0 commit comments

Comments
 (0)