Repository: google/go-github
Pull request #2594 (2022-12-07 21:58:08)

Add MakeLatest parameter to support explicitly setting latest release
Fixes: #2593

This adds support for the `make_latest` parameter added to the GitHub repositories API for setting explicit releases.

https://github.blog/changelog/2022-10-21-explicitly-set-the-latest-release/
https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#update-a-release

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2594?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2594](https://codecov.io/gh/google/go-github/pull/2594?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (05df1a3) into [master](https://codecov.io/gh/google/go-github/commit/153bbc2620f5693e42fb1ae5b80d86c611bc6727?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (153bbc2) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master    #2594   +/-   ##
=======================================
  Coverage   97.98%   97.99%           
=======================================
  Files         126      126           
  Lines       10895    10897    +2     
=======================================
+ Hits        10676    10678    +2     
  Misses        150      150           
  Partials       69       69           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2594?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/repos\_releases.go](https://codecov.io/gh/google/go-github/pull/2594/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3JlcG9zX3JlbGVhc2VzLmdv) | `89.45% <100.00%> (+0.08%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 5842fd00..f2cb16ff 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/repos_releases.go b/github/repos_releases.go
index c030f04d..464c2ee1 100644
--- a/github/repos_releases.go
+++ b/github/repos_releases.go
@@ -19,12 +19,14 @@ 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"`
 
 	// The following fields are not used in EditRelease:
@@ -176,6 +178,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 +199,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 +233,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,
 	}
 


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 77fafc4e..71fc6c1f 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 7c1372cc..b60fd0ad 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)
 	}
diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go
index 77a20ffe..73a9f3a5 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 + `,