From 29a451174ec421622a7c28cc7b1dca0ea92c7c28 Mon Sep 17 00:00:00 2001 From: Franky W Date: Fri, 23 Jun 2023 09:07:34 +0200 Subject: [PATCH 1/2] Fix CreateOrUpdateOrgSecret regression introduced in v53 `CreateOrUpdateOrgSecret`'s API uses `string` for selected repository IDS while other APIs use `int`. This fixes the issue locally by implementing its own type --- github/dependabot_secrets.go | 19 ++++++++++++++++++- github/dependabot_secrets_test.go | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/github/dependabot_secrets.go b/github/dependabot_secrets.go index f87ab42c39..8ce11438a2 100644 --- a/github/dependabot_secrets.go +++ b/github/dependabot_secrets.go @@ -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("%d", 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) { diff --git a/github/dependabot_secrets_test.go b/github/dependabot_secrets_test.go index 13eac69efe..d48328846c 100644 --- a/github/dependabot_secrets_test.go +++ b/github/dependabot_secrets_test.go @@ -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) }) From d573d4724f45042203934134d1d9e47a336390c8 Mon Sep 17 00:00:00 2001 From: Franky W Date: Fri, 23 Jun 2023 19:49:16 +0200 Subject: [PATCH 2/2] Change %d to %v in Sprintf --- github/dependabot_secrets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/dependabot_secrets.go b/github/dependabot_secrets.go index 8ce11438a2..685f7bea8e 100644 --- a/github/dependabot_secrets.go +++ b/github/dependabot_secrets.go @@ -146,7 +146,7 @@ func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner, 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("%d", secret) + repoIDs[i] = fmt.Sprintf("%v", secret) } params := struct { *DependabotEncryptedSecret