diff --git a/github/dependabot_secrets.go b/github/dependabot_secrets.go index f87ab42c396..aefab2af5e3 100644 --- a/github/dependabot_secrets.go +++ b/github/dependabot_secrets.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "strconv" ) func (s *DependabotService) getPublicKey(ctx context.Context, url string) (*PublicKey, *Response, error) { @@ -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) {