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 1966adb011e..b55d3667a6e 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 { @@ -35102,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. @@ -35126,52 +35198,60 @@ func (r *RepositoryRelease) GetBody() string { return *r.Body } -// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetCreatedAt() Timestamp { - if r == nil || r.CreatedAt == nil { - return Timestamp{} +// 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.CreatedAt + return *r.BodyHTML } -// GetDiscussionCategoryName returns the DiscussionCategoryName field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetDiscussionCategoryName() string { - if r == nil || r.DiscussionCategoryName == nil { +// 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.DiscussionCategoryName + return *r.BodyText } -// GetDraft returns the Draft field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetDraft() bool { - if r == nil || r.Draft == nil { - return false +// GetCreatedAt returns the CreatedAt field. +func (r *RepositoryRelease) GetCreatedAt() Timestamp { + if r == nil { + return Timestamp{} } - return *r.Draft + return r.CreatedAt } -// GetGenerateReleaseNotes returns the GenerateReleaseNotes field if it's non-nil, zero value otherwise. -func (r *RepositoryRelease) GetGenerateReleaseNotes() bool { - if r == nil || r.GenerateReleaseNotes == 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.DiscussionURL +} + +// GetDraft returns the Draft field. +func (r *RepositoryRelease) GetDraft() bool { + if r == nil { return false } - return *r.GenerateReleaseNotes + 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. @@ -35182,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. @@ -35198,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. @@ -35222,12 +35302,20 @@ func (r *RepositoryRelease) GetPublishedAt() Timestamp { return *r.PublishedAt } -// GetTagName returns the TagName field if it's non-nil, zero value otherwise. +// GetReactions returns the Reactions field. +func (r *RepositoryRelease) GetReactions() *Reactions { + if r == nil { + return nil + } + return r.Reactions +} + +// 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. @@ -35238,28 +35326,36 @@ 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. +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. +// 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. @@ -42430,6 +42526,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..c28c9832d70 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 @@ -44126,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() @@ -44154,56 +44247,58 @@ func TestRepositoryRelease_GetBody(tt *testing.T) { r.GetBody() } -func TestRepositoryRelease_GetCreatedAt(tt *testing.T) { +func TestRepositoryRelease_GetBodyHTML(tt *testing.T) { tt.Parallel() - var zeroValue Timestamp - r := &RepositoryRelease{CreatedAt: &zeroValue} - r.GetCreatedAt() + var zeroValue string + r := &RepositoryRelease{BodyHTML: &zeroValue} + r.GetBodyHTML() r = &RepositoryRelease{} - r.GetCreatedAt() + r.GetBodyHTML() r = nil - r.GetCreatedAt() + r.GetBodyHTML() } -func TestRepositoryRelease_GetDiscussionCategoryName(tt *testing.T) { +func TestRepositoryRelease_GetBodyText(tt *testing.T) { tt.Parallel() var zeroValue string - r := &RepositoryRelease{DiscussionCategoryName: &zeroValue} - r.GetDiscussionCategoryName() + r := &RepositoryRelease{BodyText: &zeroValue} + r.GetBodyText() r = &RepositoryRelease{} - r.GetDiscussionCategoryName() + r.GetBodyText() r = nil - r.GetDiscussionCategoryName() + r.GetBodyText() } -func TestRepositoryRelease_GetDraft(tt *testing.T) { +func TestRepositoryRelease_GetCreatedAt(tt *testing.T) { tt.Parallel() - var zeroValue bool - r := &RepositoryRelease{Draft: &zeroValue} - r.GetDraft() - r = &RepositoryRelease{} - r.GetDraft() + r := &RepositoryRelease{} + r.GetCreatedAt() r = nil - r.GetDraft() + r.GetCreatedAt() } -func TestRepositoryRelease_GetGenerateReleaseNotes(tt *testing.T) { +func TestRepositoryRelease_GetDiscussionURL(tt *testing.T) { tt.Parallel() - var zeroValue bool - r := &RepositoryRelease{GenerateReleaseNotes: &zeroValue} - r.GetGenerateReleaseNotes() + var zeroValue string + r := &RepositoryRelease{DiscussionURL: &zeroValue} + r.GetDiscussionURL() r = &RepositoryRelease{} - r.GetGenerateReleaseNotes() + r.GetDiscussionURL() + r = nil + r.GetDiscussionURL() +} + +func TestRepositoryRelease_GetDraft(tt *testing.T) { + tt.Parallel() + r := &RepositoryRelease{} + r.GetDraft() r = nil - r.GetGenerateReleaseNotes() + r.GetDraft() } 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() @@ -44211,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() @@ -44231,15 +44323,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) { @@ -44255,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() @@ -44266,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() @@ -44286,12 +44372,17 @@ 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 - r := &RepositoryRelease{TagName: &zeroValue} - r.GetTagName() - r = &RepositoryRelease{} + r := &RepositoryRelease{} r.GetTagName() r = nil r.GetTagName() @@ -44310,21 +44401,26 @@ 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() } -func TestRepositoryRelease_GetUploadURL(tt *testing.T) { +func TestRepositoryRelease_GetUpdatedAt(tt *testing.T) { tt.Parallel() - var zeroValue string - r := &RepositoryRelease{UploadURL: &zeroValue} - r.GetUploadURL() + 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() + r := &RepositoryRelease{} r.GetUploadURL() r = nil r.GetUploadURL() @@ -44332,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() @@ -53255,6 +53348,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..0063cf44cb2 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: "", + TargetCommitish: "", + Name: Ptr(""), + Body: Ptr(""), + Draft: false, + Prerelease: false, + Immutable: Ptr(false), + ID: 0, + CreatedAt: Timestamp{}, + PublishedAt: &Timestamp{}, + UpdatedAt: &Timestamp{}, + URL: "", + HTMLURL: "", + AssetsURL: "", + UploadURL: "", + ZipballURL: Ptr(""), + TarballURL: Ptr(""), + Author: &User{}, + NodeID: "", + 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..8a018964fc5 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 } @@ -503,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 { @@ -514,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 723f7777801..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) } @@ -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}`) }) @@ -240,16 +222,12 @@ 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) } 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))} + want := &RepositoryRelease{ID: 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) } @@ -801,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() @@ -831,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() @@ -870,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) @@ -889,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) @@ -916,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) @@ -953,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"}`},