diff --git a/github/github-accessors.go b/github/github-accessors.go index b5c01e9989b..4b1aaf55bc5 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -11134,6 +11134,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 { @@ -34950,6 +35022,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 { @@ -34958,12 +35046,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. @@ -34974,14 +35062,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 { @@ -35006,12 +35086,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. @@ -35046,6 +35126,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 { @@ -35070,6 +35158,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 { @@ -42254,6 +42350,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 fe11f19855f..36667d1443e 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -14156,6 +14156,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 @@ -43960,6 +44056,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 @@ -43971,15 +44089,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) { @@ -43993,17 +44111,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 @@ -44037,15 +44144,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) { @@ -44092,6 +44199,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 @@ -44125,6 +44240,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 @@ -53061,6 +53187,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/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 73c314d299e..f5b0d3dffee 100644 --- a/github/repos_releases.go +++ b/github/repos_releases.go @@ -19,33 +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"` - - // 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"` - 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 { @@ -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) }