Skip to content

Commit

Permalink
Fix CreateOrUpdateOrgSecret regression introduced in v53
Browse files Browse the repository at this point in the history
`CreateOrUpdateOrgSecret`'s API uses `string` for selected repository
IDS while other APIs use `int`. This fixes the issue locally by
implementing its own type.
  • Loading branch information
frankywahl committed Jun 23, 2023
1 parent 187e6e3 commit b18dcbe
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion github/dependabot_secrets.go
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"fmt"
"strconv"
)

func (s *DependabotService) getPublicKey(ctx context.Context, url string) (*PublicKey, *Response, error) {
Expand Down Expand Up @@ -144,8 +145,29 @@ 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] = strconv.Itoa(int(secret))
}
params := struct {
*DependabotEncryptedSecret
SelectedRepositoryIDs []string `json:"selected_repository_ids,omitempty"`
}{
DependabotEncryptedSecret: eSecret,
SelectedRepositoryIDs: repoIDs,
}

putSecret := func(ctx context.Context, url string, eSecret interface{}) (*Response, error) {
req, err := s.client.NewRequest("PUT", url, eSecret)
if err != nil {
return nil, err
}

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

url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, eSecret.Name)
return s.putSecret(ctx, url, eSecret)
return putSecret(ctx, url, params)
}

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

0 comments on commit b18dcbe

Please sign in to comment.