From a63c3c76cd1f2fc08c3b1196051f001a4e3c85db Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Fri, 26 Jun 2026 07:15:41 +0000 Subject: [PATCH 1/3] refactor!: Add release request types and rename EditRelease to UpdateRelease Introduce dedicated CreateReleaseRequest and UpdateReleaseRequest types for the bodies of RepositoriesService.CreateRelease and RepositoriesService.UpdateRelease, replacing the *RepositoryRelease parameter that also carried response-only fields. The new types are passed by value and serialized directly, dropping the internal repositoryReleaseRequest remap. EditRelease is renamed to UpdateRelease for naming consistency. This follows the value-parameter pattern established by the merged #3654, #3794 and #4320, the Edit -> Update rename from #4320, and the dedicated *Request body convention already used across the package (e.g. CreateHostedRunnerRequest). The runtime nil checks are removed since a value parameter makes them unnecessary. No deprecated wrappers are added (clean break). Updates #3644. --- github/github-accessors.go | 136 +++++++++++++++++++++++ github/github-accessors_test.go | 184 ++++++++++++++++++++++++++++++++ github/repos_releases.go | 84 +++++---------- github/repos_releases_test.go | 69 +++--------- 4 files changed, 359 insertions(+), 114 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 1966adb011e..a7770fae118 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -11294,6 +11294,78 @@ func (c *CreateRef) GetSHA() string { return c.SHA } +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetBody() string { + if c == nil || c.Body == nil { + return "" + } + return *c.Body +} + +// GetDiscussionCategoryName returns the DiscussionCategoryName field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetDiscussionCategoryName() string { + if c == nil || c.DiscussionCategoryName == nil { + return "" + } + return *c.DiscussionCategoryName +} + +// GetDraft returns the Draft field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetDraft() bool { + if c == nil || c.Draft == nil { + return false + } + return *c.Draft +} + +// GetGenerateReleaseNotes returns the GenerateReleaseNotes field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetGenerateReleaseNotes() bool { + if c == nil || c.GenerateReleaseNotes == nil { + return false + } + return *c.GenerateReleaseNotes +} + +// GetMakeLatest returns the MakeLatest field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetMakeLatest() string { + if c == nil || c.MakeLatest == nil { + return "" + } + return *c.MakeLatest +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetName() string { + if c == nil || c.Name == nil { + return "" + } + return *c.Name +} + +// GetPrerelease returns the Prerelease field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetPrerelease() bool { + if c == nil || c.Prerelease == nil { + return false + } + return *c.Prerelease +} + +// GetTagName returns the TagName field. +func (c *CreateReleaseRequest) GetTagName() string { + if c == nil { + return "" + } + return c.TagName +} + +// GetTargetCommitish returns the TargetCommitish field if it's non-nil, zero value otherwise. +func (c *CreateReleaseRequest) GetTargetCommitish() string { + if c == nil || c.TargetCommitish == nil { + return "" + } + return *c.TargetCommitish +} + // GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise. func (c *CreateRunnerGroupRequest) GetAllowsPublicRepositories() bool { if c == nil || c.AllowsPublicRepositories == nil { @@ -42430,6 +42502,70 @@ func (u *UpdateRef) GetSHA() string { return u.SHA } +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetBody() string { + if u == nil || u.Body == nil { + return "" + } + return *u.Body +} + +// GetDiscussionCategoryName returns the DiscussionCategoryName field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetDiscussionCategoryName() string { + if u == nil || u.DiscussionCategoryName == nil { + return "" + } + return *u.DiscussionCategoryName +} + +// GetDraft returns the Draft field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetDraft() bool { + if u == nil || u.Draft == nil { + return false + } + return *u.Draft +} + +// GetMakeLatest returns the MakeLatest field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetMakeLatest() string { + if u == nil || u.MakeLatest == nil { + return "" + } + return *u.MakeLatest +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetName() string { + if u == nil || u.Name == nil { + return "" + } + return *u.Name +} + +// GetPrerelease returns the Prerelease field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetPrerelease() bool { + if u == nil || u.Prerelease == nil { + return false + } + return *u.Prerelease +} + +// GetTagName returns the TagName field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetTagName() string { + if u == nil || u.TagName == nil { + return "" + } + return *u.TagName +} + +// GetTargetCommitish returns the TargetCommitish field if it's non-nil, zero value otherwise. +func (u *UpdateReleaseRequest) GetTargetCommitish() string { + if u == nil || u.TargetCommitish == nil { + return "" + } + return *u.TargetCommitish +} + // GetUpdateAllowsFetchAndMerge returns the UpdateAllowsFetchAndMerge field. func (u *UpdateRuleParameters) GetUpdateAllowsFetchAndMerge() bool { if u == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 37fc83b8fb9..41d665295d0 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -14334,6 +14334,102 @@ func TestCreateRef_GetSHA(tt *testing.T) { c.GetSHA() } +func TestCreateReleaseRequest_GetBody(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateReleaseRequest{Body: &zeroValue} + c.GetBody() + c = &CreateReleaseRequest{} + c.GetBody() + c = nil + c.GetBody() +} + +func TestCreateReleaseRequest_GetDiscussionCategoryName(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateReleaseRequest{DiscussionCategoryName: &zeroValue} + c.GetDiscussionCategoryName() + c = &CreateReleaseRequest{} + c.GetDiscussionCategoryName() + c = nil + c.GetDiscussionCategoryName() +} + +func TestCreateReleaseRequest_GetDraft(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &CreateReleaseRequest{Draft: &zeroValue} + c.GetDraft() + c = &CreateReleaseRequest{} + c.GetDraft() + c = nil + c.GetDraft() +} + +func TestCreateReleaseRequest_GetGenerateReleaseNotes(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &CreateReleaseRequest{GenerateReleaseNotes: &zeroValue} + c.GetGenerateReleaseNotes() + c = &CreateReleaseRequest{} + c.GetGenerateReleaseNotes() + c = nil + c.GetGenerateReleaseNotes() +} + +func TestCreateReleaseRequest_GetMakeLatest(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateReleaseRequest{MakeLatest: &zeroValue} + c.GetMakeLatest() + c = &CreateReleaseRequest{} + c.GetMakeLatest() + c = nil + c.GetMakeLatest() +} + +func TestCreateReleaseRequest_GetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateReleaseRequest{Name: &zeroValue} + c.GetName() + c = &CreateReleaseRequest{} + c.GetName() + c = nil + c.GetName() +} + +func TestCreateReleaseRequest_GetPrerelease(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &CreateReleaseRequest{Prerelease: &zeroValue} + c.GetPrerelease() + c = &CreateReleaseRequest{} + c.GetPrerelease() + c = nil + c.GetPrerelease() +} + +func TestCreateReleaseRequest_GetTagName(tt *testing.T) { + tt.Parallel() + c := &CreateReleaseRequest{} + c.GetTagName() + c = nil + c.GetTagName() +} + +func TestCreateReleaseRequest_GetTargetCommitish(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateReleaseRequest{TargetCommitish: &zeroValue} + c.GetTargetCommitish() + c = &CreateReleaseRequest{} + c.GetTargetCommitish() + c = nil + c.GetTargetCommitish() +} + func TestCreateRunnerGroupRequest_GetAllowsPublicRepositories(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -53255,6 +53351,94 @@ func TestUpdateRef_GetSHA(tt *testing.T) { u.GetSHA() } +func TestUpdateReleaseRequest_GetBody(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateReleaseRequest{Body: &zeroValue} + u.GetBody() + u = &UpdateReleaseRequest{} + u.GetBody() + u = nil + u.GetBody() +} + +func TestUpdateReleaseRequest_GetDiscussionCategoryName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateReleaseRequest{DiscussionCategoryName: &zeroValue} + u.GetDiscussionCategoryName() + u = &UpdateReleaseRequest{} + u.GetDiscussionCategoryName() + u = nil + u.GetDiscussionCategoryName() +} + +func TestUpdateReleaseRequest_GetDraft(tt *testing.T) { + tt.Parallel() + var zeroValue bool + u := &UpdateReleaseRequest{Draft: &zeroValue} + u.GetDraft() + u = &UpdateReleaseRequest{} + u.GetDraft() + u = nil + u.GetDraft() +} + +func TestUpdateReleaseRequest_GetMakeLatest(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateReleaseRequest{MakeLatest: &zeroValue} + u.GetMakeLatest() + u = &UpdateReleaseRequest{} + u.GetMakeLatest() + u = nil + u.GetMakeLatest() +} + +func TestUpdateReleaseRequest_GetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateReleaseRequest{Name: &zeroValue} + u.GetName() + u = &UpdateReleaseRequest{} + u.GetName() + u = nil + u.GetName() +} + +func TestUpdateReleaseRequest_GetPrerelease(tt *testing.T) { + tt.Parallel() + var zeroValue bool + u := &UpdateReleaseRequest{Prerelease: &zeroValue} + u.GetPrerelease() + u = &UpdateReleaseRequest{} + u.GetPrerelease() + u = nil + u.GetPrerelease() +} + +func TestUpdateReleaseRequest_GetTagName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateReleaseRequest{TagName: &zeroValue} + u.GetTagName() + u = &UpdateReleaseRequest{} + u.GetTagName() + u = nil + u.GetTagName() +} + +func TestUpdateReleaseRequest_GetTargetCommitish(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateReleaseRequest{TargetCommitish: &zeroValue} + u.GetTargetCommitish() + u = &UpdateReleaseRequest{} + u.GetTargetCommitish() + u = nil + u.GetTargetCommitish() +} + func TestUpdateRuleParameters_GetUpdateAllowsFetchAndMerge(tt *testing.T) { tt.Parallel() u := &UpdateRuleParameters{} diff --git a/github/repos_releases.go b/github/repos_releases.go index 73c314d299e..53e5189f1a6 100644 --- a/github/repos_releases.go +++ b/github/repos_releases.go @@ -29,10 +29,8 @@ type RepositoryRelease struct { MakeLatest *string `json:"make_latest,omitempty"` DiscussionCategoryName *string `json:"discussion_category_name,omitempty"` - // The following fields are not used in EditRelease: GenerateReleaseNotes *bool `json:"generate_release_notes,omitempty"` - // The following fields are not used in CreateRelease or EditRelease: ID *int64 `json:"id,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` PublishedAt *Timestamp `json:"published_at,omitempty"` @@ -179,52 +177,42 @@ func (s *RepositoriesService) getSingleRelease(ctx context.Context, url string) return release, resp, nil } -// repositoryReleaseRequest is a subset of RepositoryRelease and -// is used internally by CreateRelease and EditRelease to pass -// 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"` +// CreateReleaseRequest represents a request to create a release in a repository. +type CreateReleaseRequest struct { + TagName string `json:"tag_name"` + 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 can be one of: "true", "false", or "legacy". MakeLatest *string `json:"make_latest,omitempty"` + DiscussionCategoryName *string `json:"discussion_category_name,omitempty"` GenerateReleaseNotes *bool `json:"generate_release_notes,omitempty"` +} + +// UpdateReleaseRequest represents a request to update a release in a repository. +type UpdateReleaseRequest 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 can be one of: "true", "false", or "legacy". + MakeLatest *string `json:"make_latest,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?apiVersion=2022-11-28#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") - } - +func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, body CreateReleaseRequest) (*RepositoryRelease, *Response, error) { u := fmt.Sprintf("repos/%v/%v/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(ctx, "POST", u, releaseReq) + req, err := s.client.NewRequest(ctx, "POST", u, body) if err != nil { return nil, nil, err } @@ -238,33 +226,15 @@ func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo str return r, resp, nil } -// EditRelease edits a repository release. -// -// Note that only a subset of the release fields are used. -// See RepositoryRelease for more information. +// UpdateRelease updates a repository release. // // GitHub API docs: https://docs.github.com/rest/releases/releases?apiVersion=2022-11-28#update-a-release // //meta:operation PATCH /repos/{owner}/{repo}/releases/{release_id} -func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo string, id int64, release *RepositoryRelease) (*RepositoryRelease, *Response, error) { - if release == nil { - return nil, nil, errors.New("release must be provided") - } - +func (s *RepositoriesService) UpdateRelease(ctx context.Context, owner, repo string, id int64, body UpdateReleaseRequest) (*RepositoryRelease, *Response, error) { u := fmt.Sprintf("repos/%v/%v/releases/%v", owner, repo, id) - 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, - } - - req, err := s.client.NewRequest(ctx, "PATCH", u, releaseReq) + req, err := s.client.NewRequest(ctx, "PATCH", u, body) if err != nil { return nil, nil, err } diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go index 723f7777801..fa1a542ba46 100644 --- a/github/repos_releases_test.go +++ b/github/repos_releases_test.go @@ -203,34 +203,16 @@ func TestRepositoriesService_CreateRelease(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &RepositoryRelease{ + input := CreateReleaseRequest{ + TagName: "v1.0", Name: Ptr("v1.0"), DiscussionCategoryName: Ptr("General"), GenerateReleaseNotes: Ptr(true), - // Fields to be removed: - ID: Ptr(int64(2)), - CreatedAt: &Timestamp{referenceTime}, - PublishedAt: &Timestamp{referenceTime}, - URL: Ptr("http://url/"), - HTMLURL: Ptr("http://htmlurl/"), - AssetsURL: Ptr("http://assetsurl/"), - Assets: []*ReleaseAsset{{ID: Ptr(int64(5))}}, - UploadURL: Ptr("http://uploadurl/"), - ZipballURL: Ptr("http://zipballurl/"), - TarballURL: Ptr("http://tarballurl/"), - Author: &User{Name: Ptr("octocat")}, - NodeID: Ptr("nodeid"), - Immutable: Ptr(false), } mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - want := &repositoryReleaseRequest{ - Name: Ptr("v1.0"), - DiscussionCategoryName: Ptr("General"), - GenerateReleaseNotes: Ptr(true), - } - testJSONBody(t, r, want) + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":1}`) }) @@ -246,10 +228,6 @@ func TestRepositoriesService_CreateRelease(t *testing.T) { } const methodName = "CreateRelease" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Repositories.CreateRelease(ctx, "o", "r", nil) - return err - }) testBadOptions(t, methodName, func() (err error) { _, _, err = client.Repositories.CreateRelease(ctx, "\n", "\n", input) return err @@ -264,62 +242,39 @@ func TestRepositoriesService_CreateRelease(t *testing.T) { }) } -func TestRepositoriesService_EditRelease(t *testing.T) { +func TestRepositoriesService_UpdateRelease(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &RepositoryRelease{ + input := UpdateReleaseRequest{ Name: Ptr("n"), DiscussionCategoryName: Ptr("General"), - // Fields to be removed: - GenerateReleaseNotes: Ptr(true), - ID: Ptr(int64(2)), - CreatedAt: &Timestamp{referenceTime}, - PublishedAt: &Timestamp{referenceTime}, - URL: Ptr("http://url/"), - HTMLURL: Ptr("http://htmlurl/"), - AssetsURL: Ptr("http://assetsurl/"), - Assets: []*ReleaseAsset{{ID: Ptr(int64(5))}}, - UploadURL: Ptr("http://uploadurl/"), - ZipballURL: Ptr("http://zipballurl/"), - TarballURL: Ptr("http://tarballurl/"), - Author: &User{Name: Ptr("octocat")}, - NodeID: Ptr("nodeid"), - Immutable: Ptr(false), } mux.HandleFunc("/repos/o/r/releases/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - want := &repositoryReleaseRequest{ - Name: Ptr("n"), - DiscussionCategoryName: Ptr("General"), - } - testJSONBody(t, r, want) + testJSONBody(t, r, input) fmt.Fprint(w, `{"id":1}`) }) ctx := t.Context() - release, _, err := client.Repositories.EditRelease(ctx, "o", "r", 1, input) + release, _, err := client.Repositories.UpdateRelease(ctx, "o", "r", 1, input) if err != nil { - t.Errorf("Repositories.EditRelease returned error: %v", err) + t.Errorf("Repositories.UpdateRelease returned error: %v", err) } want := &RepositoryRelease{ID: Ptr(int64(1))} if !cmp.Equal(release, want) { - t.Errorf("Repositories.EditRelease returned = %+v, want %+v", release, want) + t.Errorf("Repositories.UpdateRelease returned = %+v, want %+v", release, want) } - const methodName = "EditRelease" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Repositories.EditRelease(ctx, "o", "r", 1, nil) - return err - }) + const methodName = "UpdateRelease" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Repositories.EditRelease(ctx, "\n", "\n", 1, input) + _, _, err = client.Repositories.UpdateRelease(ctx, "\n", "\n", 1, input) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Repositories.EditRelease(ctx, "o", "r", 1, input) + got, resp, err := client.Repositories.UpdateRelease(ctx, "o", "r", 1, input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } From 191d8ecd229836642c0a65f865acd708daf9f3e6 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Fri, 26 Jun 2026 07:15:41 +0000 Subject: [PATCH 2/3] refactor!: Align RepositoryRelease with the Release schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the input-only fields MakeLatest, DiscussionCategoryName and GenerateReleaseNotes from RepositoryRelease — these are carried by CreateReleaseRequest/UpdateReleaseRequest and are not part of the Release response schema. Add the response fields that were missing compared to the schema: UpdatedAt, BodyHTML, BodyText, MentionsCount, DiscussionURL and Reactions. Regenerate the accessors and stringify tests accordingly. --- github/github-accessors.go | 58 ++++++++++++++++++-------- github/github-accessors_test.go | 74 +++++++++++++++++++++++---------- github/github-stringify_test.go | 49 ++++++++++++---------- github/repos_releases.go | 50 +++++++++++----------- 4 files changed, 144 insertions(+), 87 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index a7770fae118..e69589fdeed 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -35198,6 +35198,22 @@ func (r *RepositoryRelease) GetBody() string { return *r.Body } +// GetBodyHTML returns the BodyHTML field if it's non-nil, zero value otherwise. +func (r *RepositoryRelease) GetBodyHTML() string { + if r == nil || r.BodyHTML == nil { + return "" + } + return *r.BodyHTML +} + +// GetBodyText returns the BodyText field if it's non-nil, zero value otherwise. +func (r *RepositoryRelease) GetBodyText() string { + if r == nil || r.BodyText == nil { + return "" + } + return *r.BodyText +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetCreatedAt() Timestamp { if r == nil || r.CreatedAt == nil { @@ -35206,12 +35222,12 @@ func (r *RepositoryRelease) GetCreatedAt() Timestamp { return *r.CreatedAt } -// GetDiscussionCategoryName returns the DiscussionCategoryName field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetDiscussionCategoryName() string { - if r == nil || r.DiscussionCategoryName == nil { +// GetDiscussionURL returns the DiscussionURL field if it's non-nil, zero value otherwise. +func (r *RepositoryRelease) GetDiscussionURL() string { + if r == nil || r.DiscussionURL == nil { return "" } - return *r.DiscussionCategoryName + return *r.DiscussionURL } // GetDraft returns the Draft field if it's non-nil, zero value otherwise. @@ -35222,14 +35238,6 @@ func (r *RepositoryRelease) GetDraft() bool { return *r.Draft } -// GetGenerateReleaseNotes returns the GenerateReleaseNotes field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetGenerateReleaseNotes() bool { - if r == nil || r.GenerateReleaseNotes == nil { - return false - } - return *r.GenerateReleaseNotes -} - // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetHTMLURL() string { if r == nil || r.HTMLURL == nil { @@ -35254,12 +35262,12 @@ func (r *RepositoryRelease) GetImmutable() bool { return *r.Immutable } -// GetMakeLatest returns the MakeLatest field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetMakeLatest() string { - if r == nil || r.MakeLatest == nil { - return "" +// GetMentionsCount returns the MentionsCount field if it's non-nil, zero value otherwise. +func (r *RepositoryRelease) GetMentionsCount() int { + if r == nil || r.MentionsCount == nil { + return 0 } - return *r.MakeLatest + return *r.MentionsCount } // GetName returns the Name field if it's non-nil, zero value otherwise. @@ -35294,6 +35302,14 @@ func (r *RepositoryRelease) GetPublishedAt() Timestamp { return *r.PublishedAt } +// GetReactions returns the Reactions field. +func (r *RepositoryRelease) GetReactions() *Reactions { + if r == nil { + return nil + } + return r.Reactions +} + // GetTagName returns the TagName field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetTagName() string { if r == nil || r.TagName == nil { @@ -35318,6 +35334,14 @@ func (r *RepositoryRelease) GetTargetCommitish() string { return *r.TargetCommitish } +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (r *RepositoryRelease) GetUpdatedAt() Timestamp { + if r == nil || r.UpdatedAt == nil { + return Timestamp{} + } + return *r.UpdatedAt +} + // GetUploadURL returns the UploadURL field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetUploadURL() string { if r == nil || r.UploadURL == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 41d665295d0..14eb9ef546d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -44250,6 +44250,28 @@ func TestRepositoryRelease_GetBody(tt *testing.T) { r.GetBody() } +func TestRepositoryRelease_GetBodyHTML(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRelease{BodyHTML: &zeroValue} + r.GetBodyHTML() + r = &RepositoryRelease{} + r.GetBodyHTML() + r = nil + r.GetBodyHTML() +} + +func TestRepositoryRelease_GetBodyText(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRelease{BodyText: &zeroValue} + r.GetBodyText() + r = &RepositoryRelease{} + r.GetBodyText() + r = nil + r.GetBodyText() +} + func TestRepositoryRelease_GetCreatedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp @@ -44261,15 +44283,15 @@ func TestRepositoryRelease_GetCreatedAt(tt *testing.T) { r.GetCreatedAt() } -func TestRepositoryRelease_GetDiscussionCategoryName(tt *testing.T) { +func TestRepositoryRelease_GetDiscussionURL(tt *testing.T) { tt.Parallel() var zeroValue string - r := &RepositoryRelease{DiscussionCategoryName: &zeroValue} - r.GetDiscussionCategoryName() + r := &RepositoryRelease{DiscussionURL: &zeroValue} + r.GetDiscussionURL() r = &RepositoryRelease{} - r.GetDiscussionCategoryName() + r.GetDiscussionURL() r = nil - r.GetDiscussionCategoryName() + r.GetDiscussionURL() } func TestRepositoryRelease_GetDraft(tt *testing.T) { @@ -44283,17 +44305,6 @@ func TestRepositoryRelease_GetDraft(tt *testing.T) { r.GetDraft() } -func TestRepositoryRelease_GetGenerateReleaseNotes(tt *testing.T) { - tt.Parallel() - var zeroValue bool - r := &RepositoryRelease{GenerateReleaseNotes: &zeroValue} - r.GetGenerateReleaseNotes() - r = &RepositoryRelease{} - r.GetGenerateReleaseNotes() - r = nil - r.GetGenerateReleaseNotes() -} - func TestRepositoryRelease_GetHTMLURL(tt *testing.T) { tt.Parallel() var zeroValue string @@ -44327,15 +44338,15 @@ func TestRepositoryRelease_GetImmutable(tt *testing.T) { r.GetImmutable() } -func TestRepositoryRelease_GetMakeLatest(tt *testing.T) { +func TestRepositoryRelease_GetMentionsCount(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{MakeLatest: &zeroValue} - r.GetMakeLatest() + var zeroValue int + r := &RepositoryRelease{MentionsCount: &zeroValue} + r.GetMentionsCount() r = &RepositoryRelease{} - r.GetMakeLatest() + r.GetMentionsCount() r = nil - r.GetMakeLatest() + r.GetMentionsCount() } func TestRepositoryRelease_GetName(tt *testing.T) { @@ -44382,6 +44393,14 @@ func TestRepositoryRelease_GetPublishedAt(tt *testing.T) { r.GetPublishedAt() } +func TestRepositoryRelease_GetReactions(tt *testing.T) { + tt.Parallel() + r := &RepositoryRelease{} + r.GetReactions() + r = nil + r.GetReactions() +} + func TestRepositoryRelease_GetTagName(tt *testing.T) { tt.Parallel() var zeroValue string @@ -44415,6 +44434,17 @@ func TestRepositoryRelease_GetTargetCommitish(tt *testing.T) { r.GetTargetCommitish() } +func TestRepositoryRelease_GetUpdatedAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + r := &RepositoryRelease{UpdatedAt: &zeroValue} + r.GetUpdatedAt() + r = &RepositoryRelease{} + r.GetUpdatedAt() + r = nil + r.GetUpdatedAt() +} + func TestRepositoryRelease_GetUploadURL(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index f355d93a720..e6ebba67e5b 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -2139,29 +2139,32 @@ func TestRepositoryParticipation_String(t *testing.T) { func TestRepositoryRelease_String(t *testing.T) { t.Parallel() v := RepositoryRelease{ - TagName: Ptr(""), - TargetCommitish: Ptr(""), - Name: Ptr(""), - Body: Ptr(""), - Draft: Ptr(false), - Prerelease: Ptr(false), - MakeLatest: Ptr(""), - DiscussionCategoryName: Ptr(""), - GenerateReleaseNotes: Ptr(false), - ID: Ptr(int64(0)), - CreatedAt: &Timestamp{}, - PublishedAt: &Timestamp{}, - URL: Ptr(""), - HTMLURL: Ptr(""), - AssetsURL: Ptr(""), - UploadURL: Ptr(""), - ZipballURL: Ptr(""), - TarballURL: Ptr(""), - Author: &User{}, - NodeID: Ptr(""), - Immutable: Ptr(false), - } - want := `github.RepositoryRelease{TagName:"", TargetCommitish:"", Name:"", Body:"", Draft:false, Prerelease:false, MakeLatest:"", DiscussionCategoryName:"", GenerateReleaseNotes:false, ID:0, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, PublishedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, URL:"", HTMLURL:"", AssetsURL:"", UploadURL:"", ZipballURL:"", TarballURL:"", Author:github.User{}, NodeID:"", Immutable:false}` + TagName: Ptr(""), + TargetCommitish: Ptr(""), + Name: Ptr(""), + Body: Ptr(""), + Draft: Ptr(false), + Prerelease: Ptr(false), + Immutable: Ptr(false), + ID: Ptr(int64(0)), + CreatedAt: &Timestamp{}, + PublishedAt: &Timestamp{}, + UpdatedAt: &Timestamp{}, + URL: Ptr(""), + HTMLURL: Ptr(""), + AssetsURL: Ptr(""), + UploadURL: Ptr(""), + ZipballURL: Ptr(""), + TarballURL: Ptr(""), + Author: &User{}, + NodeID: Ptr(""), + BodyHTML: Ptr(""), + BodyText: Ptr(""), + MentionsCount: Ptr(0), + DiscussionURL: Ptr(""), + Reactions: &Reactions{}, + } + want := `github.RepositoryRelease{TagName:"", TargetCommitish:"", Name:"", Body:"", Draft:false, Prerelease:false, Immutable:false, ID:0, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, PublishedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, URL:"", HTMLURL:"", AssetsURL:"", UploadURL:"", ZipballURL:"", TarballURL:"", Author:github.User{}, NodeID:"", BodyHTML:"", BodyText:"", MentionsCount:0, DiscussionURL:"", Reactions:github.Reactions{}}` if got := v.String(); got != want { t.Errorf("RepositoryRelease.String = %v, want %v", got, want) } diff --git a/github/repos_releases.go b/github/repos_releases.go index 53e5189f1a6..f5b0d3dffee 100644 --- a/github/repos_releases.go +++ b/github/repos_releases.go @@ -19,31 +19,31 @@ import ( // RepositoryRelease represents a GitHub release in a repository. type RepositoryRelease 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 can be one of: "true", "false", or "legacy". - MakeLatest *string `json:"make_latest,omitempty"` - DiscussionCategoryName *string `json:"discussion_category_name,omitempty"` - - GenerateReleaseNotes *bool `json:"generate_release_notes,omitempty"` - - ID *int64 `json:"id,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - PublishedAt *Timestamp `json:"published_at,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - AssetsURL *string `json:"assets_url,omitempty"` - Assets []*ReleaseAsset `json:"assets,omitempty"` - UploadURL *string `json:"upload_url,omitempty"` - ZipballURL *string `json:"zipball_url,omitempty"` - TarballURL *string `json:"tarball_url,omitempty"` - Author *User `json:"author,omitempty"` - NodeID *string `json:"node_id,omitempty"` - Immutable *bool `json:"immutable,omitempty"` + TagName *string `json:"tag_name"` + TargetCommitish *string `json:"target_commitish"` + Name *string `json:"name"` + Body *string `json:"body,omitempty"` + Draft *bool `json:"draft"` + Prerelease *bool `json:"prerelease"` + Immutable *bool `json:"immutable,omitempty"` + ID *int64 `json:"id"` + CreatedAt *Timestamp `json:"created_at"` + PublishedAt *Timestamp `json:"published_at"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + URL *string `json:"url"` + HTMLURL *string `json:"html_url"` + AssetsURL *string `json:"assets_url"` + Assets []*ReleaseAsset `json:"assets"` + UploadURL *string `json:"upload_url"` + ZipballURL *string `json:"zipball_url"` + TarballURL *string `json:"tarball_url"` + Author *User `json:"author"` + NodeID *string `json:"node_id"` + BodyHTML *string `json:"body_html,omitempty"` + BodyText *string `json:"body_text,omitempty"` + MentionsCount *int `json:"mentions_count,omitempty"` + DiscussionURL *string `json:"discussion_url,omitempty"` + Reactions *Reactions `json:"reactions,omitempty"` } func (r RepositoryRelease) String() string { From a24cfe7344177dcdda0751f6a172d79ed23426b4 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Fri, 26 Jun 2026 07:50:03 +0000 Subject: [PATCH 3/3] refactor!: Use value types for required non-nullable release fields Convert the required, non-nullable scalar fields of RepositoryRelease to value types: TagName, TargetCommitish, Draft, Prerelease, ID, CreatedAt, URL, HTMLURL, AssetsURL, UploadURL and NodeID. Draft and Prerelease are required, non-nullable booleans in the Release schema, so they become value bool. To support a value bool zero value, teach gen-stringify-test.go's processZeroValue to render it (previously only the *bool form was handled). The nullable required fields (Name, PublishedAt, ZipballURL, TarballURL) stay pointers so they can represent null, and Author stays *User per the nested-object convention. Regenerate the accessors and stringify tests. --- github/gen-stringify-test.go | 2 + github/github-accessors.go | 66 ++++++++++++++++----------------- github/github-accessors_test.go | 55 ++++++--------------------- github/github-stringify_test.go | 22 +++++------ github/repos_releases.go | 26 ++++++------- github/repos_releases_test.go | 24 ++++++------ github/strings_test.go | 2 +- 7 files changed, 83 insertions(+), 114 deletions(-) diff --git a/github/gen-stringify-test.go b/github/gen-stringify-test.go index ebaea533dfc..2cd9daafdbe 100644 --- a/github/gen-stringify-test.go +++ b/github/gen-stringify-test.go @@ -57,6 +57,8 @@ var ( }, "processZeroValue": func(v string) string { switch v { + case "false": + return "false" case "Ptr(false)": return "false" case "Ptr(0.0)": diff --git a/github/github-accessors.go b/github/github-accessors.go index e69589fdeed..b55d3667a6e 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -35174,12 +35174,12 @@ func (r *RepositoryRelease) GetAssets() []*ReleaseAsset { return r.Assets } -// GetAssetsURL returns the AssetsURL field if it's non-nil, zero value otherwise. +// GetAssetsURL returns the AssetsURL field. func (r *RepositoryRelease) GetAssetsURL() string { - if r == nil || r.AssetsURL == nil { + if r == nil { return "" } - return *r.AssetsURL + return r.AssetsURL } // GetAuthor returns the Author field. @@ -35214,12 +35214,12 @@ func (r *RepositoryRelease) GetBodyText() string { return *r.BodyText } -// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +// GetCreatedAt returns the CreatedAt field. func (r *RepositoryRelease) GetCreatedAt() Timestamp { - if r == nil || r.CreatedAt == nil { + if r == nil { return Timestamp{} } - return *r.CreatedAt + return r.CreatedAt } // GetDiscussionURL returns the DiscussionURL field if it's non-nil, zero value otherwise. @@ -35230,28 +35230,28 @@ func (r *RepositoryRelease) GetDiscussionURL() string { return *r.DiscussionURL } -// GetDraft returns the Draft field if it's non-nil, zero value otherwise. +// GetDraft returns the Draft field. func (r *RepositoryRelease) GetDraft() bool { - if r == nil || r.Draft == nil { + if r == nil { return false } - return *r.Draft + return r.Draft } -// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +// GetHTMLURL returns the HTMLURL field. func (r *RepositoryRelease) GetHTMLURL() string { - if r == nil || r.HTMLURL == nil { + if r == nil { return "" } - return *r.HTMLURL + return r.HTMLURL } -// GetID returns the ID field if it's non-nil, zero value otherwise. +// GetID returns the ID field. func (r *RepositoryRelease) GetID() int64 { - if r == nil || r.ID == nil { + if r == nil { return 0 } - return *r.ID + return r.ID } // GetImmutable returns the Immutable field if it's non-nil, zero value otherwise. @@ -35278,20 +35278,20 @@ func (r *RepositoryRelease) GetName() string { return *r.Name } -// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +// GetNodeID returns the NodeID field. func (r *RepositoryRelease) GetNodeID() string { - if r == nil || r.NodeID == nil { + if r == nil { return "" } - return *r.NodeID + return r.NodeID } -// GetPrerelease returns the Prerelease field if it's non-nil, zero value otherwise. +// GetPrerelease returns the Prerelease field. func (r *RepositoryRelease) GetPrerelease() bool { - if r == nil || r.Prerelease == nil { + if r == nil { return false } - return *r.Prerelease + return r.Prerelease } // GetPublishedAt returns the PublishedAt field if it's non-nil, zero value otherwise. @@ -35310,12 +35310,12 @@ func (r *RepositoryRelease) GetReactions() *Reactions { return r.Reactions } -// GetTagName returns the TagName field if it's non-nil, zero value otherwise. +// GetTagName returns the TagName field. func (r *RepositoryRelease) GetTagName() string { - if r == nil || r.TagName == nil { + if r == nil { return "" } - return *r.TagName + return r.TagName } // GetTarballURL returns the TarballURL field if it's non-nil, zero value otherwise. @@ -35326,12 +35326,12 @@ func (r *RepositoryRelease) GetTarballURL() string { return *r.TarballURL } -// GetTargetCommitish returns the TargetCommitish field if it's non-nil, zero value otherwise. +// GetTargetCommitish returns the TargetCommitish field. func (r *RepositoryRelease) GetTargetCommitish() string { - if r == nil || r.TargetCommitish == nil { + if r == nil { return "" } - return *r.TargetCommitish + return r.TargetCommitish } // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. @@ -35342,20 +35342,20 @@ func (r *RepositoryRelease) GetUpdatedAt() Timestamp { return *r.UpdatedAt } -// GetUploadURL returns the UploadURL field if it's non-nil, zero value otherwise. +// GetUploadURL returns the UploadURL field. func (r *RepositoryRelease) GetUploadURL() string { - if r == nil || r.UploadURL == nil { + if r == nil { return "" } - return *r.UploadURL + return r.UploadURL } -// GetURL returns the URL field if it's non-nil, zero value otherwise. +// GetURL returns the URL field. func (r *RepositoryRelease) GetURL() string { - if r == nil || r.URL == nil { + if r == nil { return "" } - return *r.URL + return r.URL } // GetZipballURL returns the ZipballURL field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 14eb9ef546d..c28c9832d70 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -44222,10 +44222,7 @@ func TestRepositoryRelease_GetAssets(tt *testing.T) { func TestRepositoryRelease_GetAssetsURL(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{AssetsURL: &zeroValue} - r.GetAssetsURL() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetAssetsURL() r = nil r.GetAssetsURL() @@ -44274,10 +44271,7 @@ func TestRepositoryRelease_GetBodyText(tt *testing.T) { func TestRepositoryRelease_GetCreatedAt(tt *testing.T) { tt.Parallel() - var zeroValue Timestamp - r := &RepositoryRelease{CreatedAt: &zeroValue} - r.GetCreatedAt() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetCreatedAt() r = nil r.GetCreatedAt() @@ -44296,10 +44290,7 @@ func TestRepositoryRelease_GetDiscussionURL(tt *testing.T) { func TestRepositoryRelease_GetDraft(tt *testing.T) { tt.Parallel() - var zeroValue bool - r := &RepositoryRelease{Draft: &zeroValue} - r.GetDraft() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetDraft() r = nil r.GetDraft() @@ -44307,10 +44298,7 @@ func TestRepositoryRelease_GetDraft(tt *testing.T) { func TestRepositoryRelease_GetHTMLURL(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{HTMLURL: &zeroValue} - r.GetHTMLURL() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetHTMLURL() r = nil r.GetHTMLURL() @@ -44318,10 +44306,7 @@ func TestRepositoryRelease_GetHTMLURL(tt *testing.T) { func TestRepositoryRelease_GetID(tt *testing.T) { tt.Parallel() - var zeroValue int64 - r := &RepositoryRelease{ID: &zeroValue} - r.GetID() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetID() r = nil r.GetID() @@ -44362,10 +44347,7 @@ func TestRepositoryRelease_GetName(tt *testing.T) { func TestRepositoryRelease_GetNodeID(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{NodeID: &zeroValue} - r.GetNodeID() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetNodeID() r = nil r.GetNodeID() @@ -44373,10 +44355,7 @@ func TestRepositoryRelease_GetNodeID(tt *testing.T) { func TestRepositoryRelease_GetPrerelease(tt *testing.T) { tt.Parallel() - var zeroValue bool - r := &RepositoryRelease{Prerelease: &zeroValue} - r.GetPrerelease() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetPrerelease() r = nil r.GetPrerelease() @@ -44403,10 +44382,7 @@ func TestRepositoryRelease_GetReactions(tt *testing.T) { func TestRepositoryRelease_GetTagName(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{TagName: &zeroValue} - r.GetTagName() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetTagName() r = nil r.GetTagName() @@ -44425,10 +44401,7 @@ func TestRepositoryRelease_GetTarballURL(tt *testing.T) { func TestRepositoryRelease_GetTargetCommitish(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{TargetCommitish: &zeroValue} - r.GetTargetCommitish() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetTargetCommitish() r = nil r.GetTargetCommitish() @@ -44447,10 +44420,7 @@ func TestRepositoryRelease_GetUpdatedAt(tt *testing.T) { func TestRepositoryRelease_GetUploadURL(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{UploadURL: &zeroValue} - r.GetUploadURL() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetUploadURL() r = nil r.GetUploadURL() @@ -44458,10 +44428,7 @@ func TestRepositoryRelease_GetUploadURL(tt *testing.T) { func TestRepositoryRelease_GetURL(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{URL: &zeroValue} - r.GetURL() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetURL() r = nil r.GetURL() diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index e6ebba67e5b..0063cf44cb2 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -2139,25 +2139,25 @@ func TestRepositoryParticipation_String(t *testing.T) { func TestRepositoryRelease_String(t *testing.T) { t.Parallel() v := RepositoryRelease{ - TagName: Ptr(""), - TargetCommitish: Ptr(""), + TagName: "", + TargetCommitish: "", Name: Ptr(""), Body: Ptr(""), - Draft: Ptr(false), - Prerelease: Ptr(false), + Draft: false, + Prerelease: false, Immutable: Ptr(false), - ID: Ptr(int64(0)), - CreatedAt: &Timestamp{}, + ID: 0, + CreatedAt: Timestamp{}, PublishedAt: &Timestamp{}, UpdatedAt: &Timestamp{}, - URL: Ptr(""), - HTMLURL: Ptr(""), - AssetsURL: Ptr(""), - UploadURL: Ptr(""), + URL: "", + HTMLURL: "", + AssetsURL: "", + UploadURL: "", ZipballURL: Ptr(""), TarballURL: Ptr(""), Author: &User{}, - NodeID: Ptr(""), + NodeID: "", BodyHTML: Ptr(""), BodyText: Ptr(""), MentionsCount: Ptr(0), diff --git a/github/repos_releases.go b/github/repos_releases.go index f5b0d3dffee..8a018964fc5 100644 --- a/github/repos_releases.go +++ b/github/repos_releases.go @@ -19,26 +19,26 @@ import ( // RepositoryRelease represents a GitHub release in a repository. type RepositoryRelease struct { - TagName *string `json:"tag_name"` - TargetCommitish *string `json:"target_commitish"` + TagName string `json:"tag_name"` + TargetCommitish string `json:"target_commitish"` Name *string `json:"name"` Body *string `json:"body,omitempty"` - Draft *bool `json:"draft"` - Prerelease *bool `json:"prerelease"` + Draft bool `json:"draft"` + Prerelease bool `json:"prerelease"` Immutable *bool `json:"immutable,omitempty"` - ID *int64 `json:"id"` - CreatedAt *Timestamp `json:"created_at"` + ID int64 `json:"id"` + CreatedAt Timestamp `json:"created_at"` PublishedAt *Timestamp `json:"published_at"` UpdatedAt *Timestamp `json:"updated_at,omitempty"` - URL *string `json:"url"` - HTMLURL *string `json:"html_url"` - AssetsURL *string `json:"assets_url"` + URL string `json:"url"` + HTMLURL string `json:"html_url"` + AssetsURL string `json:"assets_url"` Assets []*ReleaseAsset `json:"assets"` - UploadURL *string `json:"upload_url"` + UploadURL string `json:"upload_url"` ZipballURL *string `json:"zipball_url"` TarballURL *string `json:"tarball_url"` Author *User `json:"author"` - NodeID *string `json:"node_id"` + NodeID string `json:"node_id"` BodyHTML *string `json:"body_html,omitempty"` BodyText *string `json:"body_text,omitempty"` MentionsCount *int `json:"mentions_count,omitempty"` @@ -473,7 +473,7 @@ func (s *RepositoriesService) UploadReleaseAssetFromRelease( reader io.Reader, size int64, ) (*ReleaseAsset, *Response, error) { - if release == nil || release.UploadURL == nil { + if release == nil || release.UploadURL == "" { return nil, nil, errors.New("release UploadURL must be provided") } if reader == nil { @@ -484,7 +484,7 @@ func (s *RepositoriesService) UploadReleaseAssetFromRelease( } // Strip URI-template portion (e.g. "{?name,label}") if present. - uploadURL := *release.UploadURL + uploadURL := release.UploadURL if idx := strings.Index(uploadURL, "{"); idx != -1 { uploadURL = uploadURL[:idx] } diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go index fa1a542ba46..2f5e73a30ce 100644 --- a/github/repos_releases_test.go +++ b/github/repos_releases_test.go @@ -32,7 +32,7 @@ func TestRepositoriesService_ListReleases(t *testing.T) { if err != nil { t.Errorf("Repositories.ListReleases returned error: %v", err) } - want := []*RepositoryRelease{{ID: Ptr(int64(1))}} + want := []*RepositoryRelease{{ID: 1}} if !cmp.Equal(releases, want) { t.Errorf("Repositories.ListReleases returned %+v, want %+v", releases, want) } @@ -109,7 +109,7 @@ func TestRepositoriesService_GetRelease(t *testing.T) { t.Errorf("Repositories.GetRelease returned error: %v\n%v", err, resp.Body) } - want := &RepositoryRelease{ID: Ptr(int64(1)), Author: &User{Login: Ptr("l")}} + want := &RepositoryRelease{ID: 1, Author: &User{Login: Ptr("l")}} if !cmp.Equal(release, want) { t.Errorf("Repositories.GetRelease returned %+v, want %+v", release, want) } @@ -144,7 +144,7 @@ func TestRepositoriesService_GetLatestRelease(t *testing.T) { t.Errorf("Repositories.GetLatestRelease returned error: %v\n%v", err, resp.Body) } - want := &RepositoryRelease{ID: Ptr(int64(3))} + want := &RepositoryRelease{ID: 3} if !cmp.Equal(release, want) { t.Errorf("Repositories.GetLatestRelease returned %+v, want %+v", release, want) } @@ -179,7 +179,7 @@ func TestRepositoriesService_GetReleaseByTag(t *testing.T) { t.Errorf("Repositories.GetReleaseByTag returned error: %v\n%v", err, resp.Body) } - want := &RepositoryRelease{ID: Ptr(int64(13))} + want := &RepositoryRelease{ID: 13} if !cmp.Equal(release, want) { t.Errorf("Repositories.GetReleaseByTag returned %+v, want %+v", release, want) } @@ -222,7 +222,7 @@ func TestRepositoriesService_CreateRelease(t *testing.T) { t.Errorf("Repositories.CreateRelease returned error: %v", err) } - want := &RepositoryRelease{ID: Ptr(int64(1))} + want := &RepositoryRelease{ID: 1} if !cmp.Equal(release, want) { t.Errorf("Repositories.CreateRelease returned %+v, want %+v", release, want) } @@ -262,7 +262,7 @@ func TestRepositoriesService_UpdateRelease(t *testing.T) { if err != nil { t.Errorf("Repositories.UpdateRelease returned error: %v", err) } - want := &RepositoryRelease{ID: Ptr(int64(1))} + want := &RepositoryRelease{ID: 1} if !cmp.Equal(release, want) { t.Errorf("Repositories.UpdateRelease returned = %+v, want %+v", release, want) } @@ -756,7 +756,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease(t *testing.T) { // Provide a templated upload URL like GitHub returns. release := &RepositoryRelease{ - UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}"), + UploadURL: "/repos/o/r/releases/1/assets{?name,label}", } ctx := t.Context() @@ -786,7 +786,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_AbsoluteTemplate(t *t // Build an absolute URL using the test client's BaseURL. absoluteUploadURL := client.baseURL.String() + "repos/o/r/releases/1/assets{?name,label}" - release := &RepositoryRelease{UploadURL: &absoluteUploadURL} + release := &RepositoryRelease{UploadURL: absoluteUploadURL} opts := &UploadOptions{Name: "abs.txt"} ctx := t.Context() @@ -825,7 +825,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_NilReader(t *testing. t.Parallel() client, _, _ := setup(t) - release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")} + release := &RepositoryRelease{UploadURL: "/repos/o/r/releases/1/assets{?name,label}"} ctx := t.Context() _, _, err := client.Repositories.UploadReleaseAssetFromRelease(ctx, release, &UploadOptions{Name: "n.txt"}, nil, 12) @@ -844,7 +844,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_NegativeSize(t *testi t.Parallel() client, _, _ := setup(t) - release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")} + release := &RepositoryRelease{UploadURL: "/repos/o/r/releases/1/assets{?name,label}"} body := []byte("Upload me !\n") reader := bytes.NewReader(body) @@ -871,7 +871,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_NoOpts(t *testing.T) reader := bytes.NewReader(body) size := int64(len(body)) - release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")} + release := &RepositoryRelease{UploadURL: "/repos/o/r/releases/1/assets{?name,label}"} ctx := t.Context() asset, _, err := client.Repositories.UploadReleaseAssetFromRelease(ctx, release, nil, reader, size) @@ -908,7 +908,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_WithMediaType(t *test reader := bytes.NewReader(body) size := int64(len(body)) - release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")} + release := &RepositoryRelease{UploadURL: "/repos/o/r/releases/1/assets{?name,label}"} opts := &UploadOptions{Name: "n.txt", MediaType: "image/png"} diff --git a/github/strings_test.go b/github/strings_test.go index 3dfb46ea687..a8044214bba 100644 --- a/github/strings_test.go +++ b/github/strings_test.go @@ -211,7 +211,7 @@ func TestString(t *testing.T) { {RepositoryComment{ID: Ptr(int64(1))}, `github.RepositoryComment{ID:1}`}, {RepositoryCommit{SHA: Ptr("s")}, `github.RepositoryCommit{SHA:"s"}`}, {RepositoryContent{Name: Ptr("n")}, `github.RepositoryContent{Name:"n"}`}, - {RepositoryRelease{ID: Ptr(int64(1))}, `github.RepositoryRelease{ID:1}`}, + {RepositoryRelease{ID: 1}, `github.RepositoryRelease{TagName:"", TargetCommitish:"", Draft:false, Prerelease:false, ID:1, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, URL:"", HTMLURL:"", AssetsURL:"", UploadURL:"", NodeID:""}`}, {Repository{ID: Ptr(int64(1))}, `github.Repository{ID:1}`}, {Team{ID: Ptr(int64(1))}, `github.Team{ID:1}`}, {TreeEntry{SHA: Ptr("s")}, `github.TreeEntry{SHA:"s"}`},