From c2833e1d2c46e0e871f753ba96d37bd5568c4183 Mon Sep 17 00:00:00 2001 From: Chris Grau <99276511+chrisgrautealium@users.noreply.github.com> Date: Wed, 7 Dec 2022 13:05:32 -0800 Subject: [PATCH 1/3] Add MakeLatest parameter GitHub recently changed the way the latest version can be managed, to allow explicitly setting the latest release. Previously, the latest release would be the most recently created non-pre-release. https://github.blog/changelog/2022-10-21-explicitly-set-the-latest-release/ In the web UI, this shows up as two checkboxes. In the API, this is set using the make_latest parameter, which defaults to true for newly created releases. https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#update-a-release https://github.com/google/go-github/issues/2593 --- github/repos_releases.go | 4 ++++ github/repos_releases_test.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/github/repos_releases.go b/github/repos_releases.go index c030f04d9a9..3b5e895b778 100644 --- a/github/repos_releases.go +++ b/github/repos_releases.go @@ -25,6 +25,7 @@ type RepositoryRelease struct { Body *string `json:"body,omitempty"` Draft *bool `json:"draft,omitempty"` Prerelease *bool `json:"prerelease,omitempty"` + MakeLatest *string `json:"make_latest,omitempty"` DiscussionCategoryName *string `json:"discussion_category_name,omitempty"` // The following fields are not used in EditRelease: @@ -176,6 +177,7 @@ type repositoryReleaseRequest struct { Body *string `json:"body,omitempty"` Draft *bool `json:"draft,omitempty"` Prerelease *bool `json:"prerelease,omitempty"` + MakeLatest *string `json:"make_latest,omitempty"` GenerateReleaseNotes *bool `json:"generate_release_notes,omitempty"` DiscussionCategoryName *string `json:"discussion_category_name,omitempty"` } @@ -196,6 +198,7 @@ func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo str Body: release.Body, Draft: release.Draft, Prerelease: release.Prerelease, + MakeLatest: release.MakeLatest, DiscussionCategoryName: release.DiscussionCategoryName, GenerateReleaseNotes: release.GenerateReleaseNotes, } @@ -229,6 +232,7 @@ func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo strin Body: release.Body, Draft: release.Draft, Prerelease: release.Prerelease, + MakeLatest: release.MakeLatest, DiscussionCategoryName: release.DiscussionCategoryName, } diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go index 77a20ffe951..73a9f3a530d 100644 --- a/github/repos_releases_test.go +++ b/github/repos_releases_test.go @@ -708,6 +708,7 @@ func TestRepositoryReleaseRequest_Marshal(t *testing.T) { Body: String("body"), Draft: Bool(false), Prerelease: Bool(false), + MakeLatest: String("legacy"), DiscussionCategoryName: String("dcn"), } @@ -718,6 +719,7 @@ func TestRepositoryReleaseRequest_Marshal(t *testing.T) { "body": "body", "draft": false, "prerelease": false, + "make_latest": "legacy", "discussion_category_name": "dcn" }` @@ -774,6 +776,7 @@ func TestRepositoryRelease_Marshal(t *testing.T) { Body: String("body"), Draft: Bool(false), Prerelease: Bool(false), + MakeLatest: String("legacy"), DiscussionCategoryName: String("dcn"), ID: Int64(1), CreatedAt: &Timestamp{referenceTime}, @@ -796,6 +799,7 @@ func TestRepositoryRelease_Marshal(t *testing.T) { "body": "body", "draft": false, "prerelease": false, + "make_latest": "legacy", "discussion_category_name": "dcn", "id": 1, "created_at": ` + referenceTimeStr + `, From 05df1a33da3aea2a4ea46e1fa7ceb64e34d4462f Mon Sep 17 00:00:00 2001 From: Chris Grau <99276511+chrisgrautealium@users.noreply.github.com> Date: Wed, 7 Dec 2022 13:53:19 -0800 Subject: [PATCH 2/3] Update generated code per contributor's guide https://github.com/google/go-github/blob/153bbc2620f5693e42fb1ae5b80d86c611bc6727/CONTRIBUTING.md#submitting-a-patch Ran, ``` go generate github.com/google/go-github/... go test github.com/google/go-github/... go vet github.com/google/go-github/... ``` --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 10 ++++++++++ github/github-stringify_test.go | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 5842fd00624..f2cb16ff42c 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -16406,6 +16406,14 @@ func (r *RepositoryRelease) GetID() int64 { return *r.ID } +// 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 "" + } + return *r.MakeLatest +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (r *RepositoryRelease) GetName() string { if r == nil || r.Name == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 77fafc4e381..71fc6c1f88d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -19077,6 +19077,16 @@ func TestRepositoryRelease_GetID(tt *testing.T) { r.GetID() } +func TestRepositoryRelease_GetMakeLatest(tt *testing.T) { + var zeroValue string + r := &RepositoryRelease{MakeLatest: &zeroValue} + r.GetMakeLatest() + r = &RepositoryRelease{} + r.GetMakeLatest() + r = nil + r.GetMakeLatest() +} + func TestRepositoryRelease_GetName(tt *testing.T) { var zeroValue string r := &RepositoryRelease{Name: &zeroValue} diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 7c1372cc404..b60fd0ad247 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -1696,6 +1696,7 @@ func TestRepositoryRelease_String(t *testing.T) { Body: String(""), Draft: Bool(false), Prerelease: Bool(false), + MakeLatest: String(""), DiscussionCategoryName: String(""), GenerateReleaseNotes: Bool(false), ID: Int64(0), @@ -1710,7 +1711,7 @@ func TestRepositoryRelease_String(t *testing.T) { Author: &User{}, NodeID: String(""), } - want := `github.RepositoryRelease{TagName:"", TargetCommitish:"", Name:"", Body:"", Draft:false, Prerelease:false, 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:""}` + 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:""}` if got := v.String(); got != want { t.Errorf("RepositoryRelease.String = %v, want %v", got, want) } From 5f4e651eb7654bd493f4aae0a95844cd66031f5f Mon Sep 17 00:00:00 2001 From: Chris Grau <99276511+chrisgrautealium@users.noreply.github.com> Date: Wed, 7 Dec 2022 15:32:47 -0800 Subject: [PATCH 3/3] Add a comment about the accepted values for MakeLatest --- github/repos_releases.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/github/repos_releases.go b/github/repos_releases.go index 3b5e895b778..464c2ee1e2b 100644 --- a/github/repos_releases.go +++ b/github/repos_releases.go @@ -19,12 +19,13 @@ 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"` + 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"`