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

Code before:
// only the known fields for these endpoints.
//
// See https://github.com/google/go-github/issues/992 for more
// information.
type repositoryReleaseRequest struct {
	TagName                *string `json:"tag_name,omitempty"`
	TargetCommitish        *string `json:"target_commitish,omitempty"`
	Name                   *string `json:"name,omitempty"`
	Body                   *string `json:"body,omitempty"`
	Draft                  *bool   `json:"draft,omitempty"`
	Prerelease             *bool   `json:"prerelease,omitempty"`
	MakeLatest             *string `json:"make_latest,omitempty"`
	GenerateReleaseNotes   *bool   `json:"generate_release_notes,omitempty"`
	DiscussionCategoryName *string `json:"discussion_category_name,omitempty"`
}

// CreateRelease adds a new release for a repository.
//
// Note that only a subset of the release fields are used.
// See RepositoryRelease for more information.
//
// GitHub API docs: https://docs.github.com/rest/releases/releases#create-a-release
//
//meta:operation POST /repos/{owner}/{repo}/releases
func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
	u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)

	releaseReq := &repositoryReleaseRequest{
		TagName:                release.TagName,
		TargetCommitish:        release.TargetCommitish,
		Name:                   release.Name,
		Body:                   release.Body,
		Draft:                  release.Draft,
		Prerelease:             release.Prerelease,
		MakeLatest:             release.MakeLatest,
		DiscussionCategoryName: release.DiscussionCategoryName,
		GenerateReleaseNotes:   release.GenerateReleaseNotes,
	}

	req, err := s.client.NewRequest("POST", u, releaseReq)
	if err != nil {
		return nil, nil, err
	}

	r := new(RepositoryRelease)
	resp, err := s.client.Do(ctx, req, r)
	if err != nil {
		return nil, resp, err
	}
	return r, resp, nil
}

Review comment (performance):
One might question why we don't simply pass `release` by value here (and elsewhere).
Certainly this is just due to habit (or copy/paste) and not for any performance-critical reasons.
Yes, changing it now would be a breaking API change.
Thoughts?

Code after:
// only the known fields for these endpoints.
//
// See https://github.com/google/go-github/issues/992 for more
// information.
type repositoryReleaseRequest struct {
	TagName                *string `json:"tag_name,omitempty"`
	TargetCommitish        *string `json:"target_commitish,omitempty"`
	Name                   *string `json:"name,omitempty"`
	Body                   *string `json:"body,omitempty"`
	Draft                  *bool   `json:"draft,omitempty"`
	Prerelease             *bool   `json:"prerelease,omitempty"`
	MakeLatest             *string `json:"make_latest,omitempty"`
	GenerateReleaseNotes   *bool   `json:"generate_release_notes,omitempty"`
	DiscussionCategoryName *string `json:"discussion_category_name,omitempty"`
}

// CreateRelease adds a new release for a repository.
//
// Note that only a subset of the release fields are used.
// See RepositoryRelease for more information.
//
// GitHub API docs: https://docs.github.com/rest/releases/releases#create-a-release
//
//meta:operation POST /repos/{owner}/{repo}/releases
func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
	if release == nil {
		return nil, nil, errors.New("release must be provided")
	}

	u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)

	releaseReq := &repositoryReleaseRequest{
		TagName:                release.TagName,
		TargetCommitish:        release.TargetCommitish,
		Name:                   release.Name,
		Body:                   release.Body,
		Draft:                  release.Draft,
		Prerelease:             release.Prerelease,
		MakeLatest:             release.MakeLatest,
		DiscussionCategoryName: release.DiscussionCategoryName,
		GenerateReleaseNotes:   release.GenerateReleaseNotes,
	}

	req, err := s.client.NewRequest("POST", u, releaseReq)
	if err != nil {
		return nil, nil, err
	}

	r := new(RepositoryRelease)
	resp, err := s.client.Do(ctx, req, r)
	if err != nil {