Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions github/dependabot_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,7 @@ func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner,
func (s *DependabotService) CreateOrUpdateOrgSecret(ctx context.Context, org, name string, body SecretOrgRequest) (*Response, error) {
u := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, name)

var bodyOverride any = body
if len(body.SelectedRepositoryIDs) > 0 {
repoIDs := make([]string, len(body.SelectedRepositoryIDs))
for i, id := range body.SelectedRepositoryIDs {
repoIDs[i] = fmt.Sprintf("%v", id)
}

bodyOverride = struct {
SecretOrgRequest
SelectedRepositoryIDs []string `json:"selected_repository_ids,omitzero"`
}{
SecretOrgRequest: body,
SelectedRepositoryIDs: repoIDs,
}
}

req, err := s.client.NewRequest(ctx, "PUT", u, bodyOverride)
req, err := s.client.NewRequest(ctx, "PUT", u, body)
if err != nil {
return nil, err
}
Expand Down
13 changes: 1 addition & 12 deletions github/dependabot_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,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")
want := SecretOrgRequest{
EncryptedValue: input.EncryptedValue,
KeyID: input.KeyID,
Visibility: input.Visibility,
}
testJSONBody(t, r, struct {
SecretOrgRequest
SelectedRepositoryIDs []string `json:"selected_repository_ids,omitempty"`
}{
SecretOrgRequest: want,
SelectedRepositoryIDs: []string{"1296269", "1269280"},
})
testJSONBody(t, r, input)
w.WriteHeader(http.StatusCreated)
})

Expand Down
Loading