Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support explicitly marking a Release as "Latest" #6538

Merged
merged 1 commit into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/cmd/release/create/create.go
Expand Up @@ -38,6 +38,7 @@ type CreateOptions struct {
BodyProvided bool
Draft bool
Prerelease bool
IsLatest *bool

Assets []*shared.AssetForUpload

Expand Down Expand Up @@ -164,6 +165,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
cmd.Flags().StringVarP(&opts.DiscussionCategory, "discussion-category", "", "", "Start a discussion in the specified category")
cmd.Flags().BoolVarP(&opts.GenerateNotes, "generate-notes", "", false, "Automatically generate title and notes for the release")
cmd.Flags().StringVar(&opts.NotesStartTag, "notes-start-tag", "", "Tag to use as the starting point for generating release notes")
cmdutil.NilBoolFlag(cmd, &opts.IsLatest, "latest", "", "Mark this release as \"Latest\" (default: automatic based on date and version)")

return cmd
}
Expand Down Expand Up @@ -409,6 +411,10 @@ func createRun(opts *CreateOptions) error {
if opts.Target != "" {
params["target_commitish"] = opts.Target
}
if opts.IsLatest != nil {
// valid values: true/false/legacy
params["make_latest"] = fmt.Sprintf("%v", *opts.IsLatest)
}
if opts.DiscussionCategory != "" {
params["discussion_category_name"] = opts.DiscussionCategory
}
Expand Down
74 changes: 74 additions & 0 deletions pkg/cmd/release/create/create_test.go
Expand Up @@ -260,6 +260,46 @@ func Test_NewCmdCreate(t *testing.T) {
NotesStartTag: "v1.1.0",
},
},
{
name: "latest",
args: "--latest v1.1.0",
isTTY: false,
want: CreateOptions{
TagName: "v1.1.0",
Target: "",
Name: "",
Body: "",
BodyProvided: false,
Draft: false,
Prerelease: false,
IsLatest: boolPtr(true),
RepoOverride: "",
Concurrency: 5,
Assets: []*shared.AssetForUpload(nil),
GenerateNotes: false,
NotesStartTag: "",
},
},
{
name: "not latest",
args: "--latest=false v1.1.0",
isTTY: false,
want: CreateOptions{
TagName: "v1.1.0",
Target: "",
Name: "",
Body: "",
BodyProvided: false,
Draft: false,
Prerelease: false,
IsLatest: boolPtr(false),
RepoOverride: "",
Concurrency: 5,
Assets: []*shared.AssetForUpload(nil),
GenerateNotes: false,
NotesStartTag: "",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -312,6 +352,7 @@ func Test_NewCmdCreate(t *testing.T) {
assert.Equal(t, tt.want.DiscussionCategory, opts.DiscussionCategory)
assert.Equal(t, tt.want.GenerateNotes, opts.GenerateNotes)
assert.Equal(t, tt.want.NotesStartTag, opts.NotesStartTag)
assert.Equal(t, tt.want.IsLatest, opts.IsLatest)

require.Equal(t, len(tt.want.Assets), len(opts.Assets))
for i := range tt.want.Assets {
Expand Down Expand Up @@ -444,6 +485,35 @@ func Test_createRun(t *testing.T) {
wantStdout: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
wantStderr: ``,
},
{
name: "with latest",
isTTY: false,
opts: CreateOptions{
TagName: "v1.2.3",
Name: "",
Body: "",
Target: "",
IsLatest: boolPtr(true),
BodyProvided: true,
GenerateNotes: false,
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
"url": "https://api.github.com/releases/123",
"upload_url": "https://api.github.com/assets/upload",
"html_url": "https://github.com/OWNER/REPO/releases/tag/v1.2.3"
}`, func(params map[string]interface{}) {
assert.Equal(t, map[string]interface{}{
"tag_name": "v1.2.3",
"draft": false,
"prerelease": false,
"make_latest": "true",
}, params)
}))
},
wantStdout: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
wantErr: "",
},
{
name: "with generate notes",
isTTY: true,
Expand Down Expand Up @@ -1101,3 +1171,7 @@ func Test_createRun_interactive(t *testing.T) {
})
}
}

func boolPtr(b bool) *bool {
return &b
}
7 changes: 7 additions & 0 deletions pkg/cmd/release/edit/edit.go
Expand Up @@ -24,6 +24,7 @@ type EditOptions struct {
DiscussionCategory *string
Draft *bool
Prerelease *bool
IsLatest *bool
}

func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Command {
Expand Down Expand Up @@ -72,6 +73,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman

cmdutil.NilBoolFlag(cmd, &opts.Draft, "draft", "", "Save the release as a draft instead of publishing it")
cmdutil.NilBoolFlag(cmd, &opts.Prerelease, "prerelease", "", "Mark the release as a prerelease")
cmdutil.NilBoolFlag(cmd, &opts.IsLatest, "latest", "", "Explicitly mark the release as \"Latest\"")
cmdutil.NilStringFlag(cmd, &opts.Body, "notes", "n", "Release notes")
cmdutil.NilStringFlag(cmd, &opts.Name, "title", "t", "Release title")
cmdutil.NilStringFlag(cmd, &opts.DiscussionCategory, "discussion-category", "", "Start a discussion in the specified category when publishing a draft")
Expand Down Expand Up @@ -146,5 +148,10 @@ func getParams(opts *EditOptions) map[string]interface{} {
params["target_commitish"] = opts.Target
}

if opts.IsLatest != nil {
// valid values: true/false/legacy
params["make_latest"] = fmt.Sprintf("%v", *opts.IsLatest)
}

return params
}
36 changes: 36 additions & 0 deletions pkg/cmd/release/edit/edit_test.go
Expand Up @@ -102,6 +102,24 @@ func Test_NewCmdEdit(t *testing.T) {
Draft: boolPtr(false),
},
},
{
name: "latest",
args: "v1.2.3 --latest",
isTTY: false,
want: EditOptions{
TagName: "",
IsLatest: boolPtr(true),
},
},
{
name: "not latest",
args: "v1.2.3 --latest=false",
isTTY: false,
want: EditOptions{
TagName: "",
IsLatest: boolPtr(false),
},
},
{
name: "provide notes from file",
args: fmt.Sprintf(`v1.2.3 -F '%s'`, tf.Name()),
Expand Down Expand Up @@ -169,6 +187,7 @@ func Test_NewCmdEdit(t *testing.T) {
assert.Equal(t, tt.want.DiscussionCategory, opts.DiscussionCategory)
assert.Equal(t, tt.want.Draft, opts.Draft)
assert.Equal(t, tt.want.Prerelease, opts.Prerelease)
assert.Equal(t, tt.want.IsLatest, opts.IsLatest)
})
}
}
Expand Down Expand Up @@ -250,6 +269,23 @@ func Test_editRun(t *testing.T) {
wantStdout: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
wantStderr: "",
},
{
name: "edit the latest marker",
isTTY: false,
opts: EditOptions{
IsLatest: boolPtr(true),
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
mockSuccessfulEditResponse(reg, func(params map[string]interface{}) {
assert.Equal(t, map[string]interface{}{
"tag_name": "v1.2.3",
"make_latest": "true",
}, params)
})
},
wantStdout: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
wantStderr: "",
},
{
name: "edit the release name (empty)",
isTTY: true,
Expand Down