Skip to content

Commit 96726d8

Browse files
authored
Fix CreateOrUpdateOrgSecret regression introduced in v53 (#2817)
Fixes: #2816.
1 parent cd0f4b9 commit 96726d8

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

github/dependabot_secrets.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,25 @@ func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner,
144144
//
145145
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#create-or-update-an-organization-secret
146146
func (s *DependabotService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *DependabotEncryptedSecret) (*Response, error) {
147+
repoIDs := make([]string, len(eSecret.SelectedRepositoryIDs))
148+
for i, secret := range eSecret.SelectedRepositoryIDs {
149+
repoIDs[i] = fmt.Sprintf("%v", secret)
150+
}
151+
params := struct {
152+
*DependabotEncryptedSecret
153+
SelectedRepositoryIDs []string `json:"selected_repository_ids,omitempty"`
154+
}{
155+
DependabotEncryptedSecret: eSecret,
156+
SelectedRepositoryIDs: repoIDs,
157+
}
158+
147159
url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, eSecret.Name)
148-
return s.putSecret(ctx, url, eSecret)
160+
req, err := s.client.NewRequest("PUT", url, params)
161+
if err != nil {
162+
return nil, err
163+
}
164+
165+
return s.client.Do(ctx, req, nil)
149166
}
150167

151168
func (s *DependabotService) deleteSecret(ctx context.Context, url string) (*Response, error) {

github/dependabot_secrets_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ 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

0 commit comments

Comments
 (0)