Repository: google/go-github
File: github/dependabot_secrets.go (Go)

Code before:
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#create-or-update-a-repository-secret
func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *DependabotEncryptedSecret) (*Response, error) {
	url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, eSecret.Name)
	return s.putSecret(ctx, url, eSecret)
}

// CreateOrUpdateOrgSecret creates or updates an organization Dependabot secret with an encrypted value.
//
// 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 putSecret(ctx, url, params)
}

func (s *DependabotService) deleteSecret(ctx context.Context, url string) (*Response, error) {
	req, err := s.client.NewRequest("DELETE", url, nil)
	if err != nil {
		return nil, err
	}

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

// DeleteRepoSecret deletes a Dependabot secret in a repository using the secret name.
//
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#delete-a-repository-secret
func (s *DependabotService) DeleteRepoSecret(ctx context.Context, owner, repo, name string) (*Response, error) {
	url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, name)
	return s.deleteSecret(ctx, url)
}

Review comment (security):
Created this inline for now as it's the only place it's used. Happy to pull it out as an unexported function to match the `putSecret` package function (maybe `putOrgSecret`). That would require though defining a package type for `params` (for used as an input argument). I thought it was an overkill for now, so left it as such.  

Code after:
func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *DependabotEncryptedSecret) (*Response, error) {
	url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, eSecret.Name)
	return s.putSecret(ctx, url, eSecret)
}

// CreateOrUpdateOrgSecret creates or updates an organization Dependabot secret with an encrypted value.
//
// 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)
	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) {
	req, err := s.client.NewRequest("DELETE", url, nil)
	if err != nil {
		return nil, err
	}

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

// DeleteRepoSecret deletes a Dependabot secret in a repository using the secret name.
//
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#delete-a-repository-secret
func (s *DependabotService) DeleteRepoSecret(ctx context.Context, owner, repo, name string) (*Response, error) {
	url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, name)
	return s.deleteSecret(ctx, url)
}

// DeleteOrgSecret deletes a Dependabot secret in an organization using the secret name.
//
// GitHub API docs: https://docs.github.com/en/rest/dependabot/secrets#delete-an-organization-secret
func (s *DependabotService) DeleteOrgSecret(ctx context.Context, org, name string) (*Response, error) {