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

Fix CreateOrUpdateOrgSecret regression introduced in v53 #2817

Merged
merged 2 commits into from Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 18 additions & 1 deletion github/dependabot_secrets.go
Expand Up @@ -144,8 +144,25 @@ func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner,
//
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#create-or-update-an-organization-secret
func (s *DependabotService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *DependabotEncryptedSecret) (*Response, error) {
repoIDs := make([]string, len(eSecret.SelectedRepositoryIDs))
for i, secret := range eSecret.SelectedRepositoryIDs {
repoIDs[i] = fmt.Sprintf("%v", secret)
}
params := struct {
*DependabotEncryptedSecret
SelectedRepositoryIDs []string `json:"selected_repository_ids,omitempty"`
}{
DependabotEncryptedSecret: eSecret,
SelectedRepositoryIDs: repoIDs,
}

url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, eSecret.Name)
return s.putSecret(ctx, url, eSecret)
req, err := s.client.NewRequest("PUT", url, params)
if err != nil {
return nil, err
}

return s.client.Do(ctx, req, nil)
}

func (s *DependabotService) deleteSecret(ctx context.Context, url string) (*Response, error) {
Expand Down
2 changes: 1 addition & 1 deletion github/dependabot_secrets_test.go
Expand Up @@ -352,7 +352,7 @@ func TestDependabotService_CreateOrUpdateOrgSecret(t *testing.T) {
mux.HandleFunc("/orgs/o/dependabot/secrets/NAME", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"key_id":"1234","encrypted_value":"QIv=","visibility":"selected","selected_repository_ids":[1296269,1269280]}`+"\n")
testBody(t, r, `{"key_id":"1234","encrypted_value":"QIv=","visibility":"selected","selected_repository_ids":["1296269","1269280"]}`+"\n")
w.WriteHeader(http.StatusCreated)
})

Expand Down