Merge pull request #4003 from despreston/3381-release-discussions
add --discussion-category flag to release cmd
This commit is contained in:
commit
4fa984a333
2 changed files with 91 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package create
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -48,6 +49,8 @@ type CreateOptions struct {
|
|||
|
||||
// maximum number of simultaneous uploads
|
||||
Concurrency int
|
||||
|
||||
DiscussionCategory string
|
||||
}
|
||||
|
||||
func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command {
|
||||
|
|
@ -92,9 +95,16 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
|
|||
|
||||
Upload a release asset with a display label
|
||||
$ gh release create v1.2.3 '/path/to/asset.zip#My display label'
|
||||
|
||||
Create a release and start a discussion
|
||||
$ gh release create v1.2.3 --discussion-category "General"
|
||||
`),
|
||||
Args: cmdutil.MinimumArgs(1, "could not create: no tag name provided"),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if cmd.Flags().Changed("discussion-category") && opts.Draft {
|
||||
return errors.New("Discussions for draft releases not supported")
|
||||
}
|
||||
|
||||
// support `-R, --repo` override
|
||||
opts.BaseRepo = f.BaseRepo
|
||||
opts.RepoOverride, _ = cmd.Flags().GetString("repo")
|
||||
|
|
@ -132,6 +142,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
|
|||
cmd.Flags().StringVarP(&opts.Name, "title", "t", "", "Release title")
|
||||
cmd.Flags().StringVarP(&opts.Body, "notes", "n", "", "Release notes")
|
||||
cmd.Flags().StringVarP(¬esFile, "notes-file", "F", "", "Read release notes from `file`")
|
||||
cmd.Flags().StringVarP(&opts.DiscussionCategory, "discussion-category", "", "", "Start a discussion of the specified category")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
@ -268,6 +279,13 @@ func createRun(opts *CreateOptions) error {
|
|||
}
|
||||
}
|
||||
|
||||
if opts.Draft && len(opts.DiscussionCategory) > 0 {
|
||||
return fmt.Errorf(
|
||||
"%s Discussions not supported with draft releases",
|
||||
opts.IO.ColorScheme().FailureIcon(),
|
||||
)
|
||||
}
|
||||
|
||||
params := map[string]interface{}{
|
||||
"tag_name": opts.TagName,
|
||||
"draft": opts.Draft,
|
||||
|
|
@ -278,6 +296,9 @@ func createRun(opts *CreateOptions) error {
|
|||
if opts.Target != "" {
|
||||
params["target_commitish"] = opts.Target
|
||||
}
|
||||
if opts.DiscussionCategory != "" {
|
||||
params["discussion_category_name"] = opts.DiscussionCategory
|
||||
}
|
||||
|
||||
hasAssets := len(opts.Assets) > 0
|
||||
|
||||
|
|
|
|||
|
|
@ -160,6 +160,30 @@ func Test_NewCmdCreate(t *testing.T) {
|
|||
isTTY: true,
|
||||
wantErr: "could not create: no tag name provided",
|
||||
},
|
||||
{
|
||||
name: "discussion category",
|
||||
args: "v1.2.3 --discussion-category 'General'",
|
||||
isTTY: true,
|
||||
want: CreateOptions{
|
||||
TagName: "v1.2.3",
|
||||
Target: "",
|
||||
Name: "",
|
||||
Body: "",
|
||||
BodyProvided: false,
|
||||
Draft: false,
|
||||
Prerelease: false,
|
||||
RepoOverride: "",
|
||||
Concurrency: 5,
|
||||
Assets: []*shared.AssetForUpload(nil),
|
||||
DiscussionCategory: "General",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "discussion category for draft release",
|
||||
args: "v1.2.3 -d --discussion-category 'General'",
|
||||
isTTY: true,
|
||||
wantErr: "Discussions for draft releases not supported",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
@ -209,6 +233,7 @@ func Test_NewCmdCreate(t *testing.T) {
|
|||
assert.Equal(t, tt.want.Prerelease, opts.Prerelease)
|
||||
assert.Equal(t, tt.want.Concurrency, opts.Concurrency)
|
||||
assert.Equal(t, tt.want.RepoOverride, opts.RepoOverride)
|
||||
assert.Equal(t, tt.want.DiscussionCategory, opts.DiscussionCategory)
|
||||
|
||||
require.Equal(t, len(tt.want.Assets), len(opts.Assets))
|
||||
for i := range tt.want.Assets {
|
||||
|
|
@ -249,6 +274,28 @@ func Test_createRun(t *testing.T) {
|
|||
wantStdout: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
|
||||
wantStderr: ``,
|
||||
},
|
||||
{
|
||||
name: "with discussion category",
|
||||
isTTY: true,
|
||||
opts: CreateOptions{
|
||||
TagName: "v1.2.3",
|
||||
Name: "The Big 1.2",
|
||||
Body: "* Fixed bugs",
|
||||
BodyProvided: true,
|
||||
Target: "",
|
||||
DiscussionCategory: "General",
|
||||
},
|
||||
wantParams: map[string]interface{}{
|
||||
"tag_name": "v1.2.3",
|
||||
"name": "The Big 1.2",
|
||||
"body": "* Fixed bugs",
|
||||
"draft": false,
|
||||
"prerelease": false,
|
||||
"discussion_category_name": "General",
|
||||
},
|
||||
wantStdout: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
|
||||
wantStderr: ``,
|
||||
},
|
||||
{
|
||||
name: "with target commitish",
|
||||
isTTY: true,
|
||||
|
|
@ -291,6 +338,29 @@ func Test_createRun(t *testing.T) {
|
|||
wantStdout: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
|
||||
wantStderr: ``,
|
||||
},
|
||||
{
|
||||
name: "discussion category for draft release",
|
||||
isTTY: true,
|
||||
opts: CreateOptions{
|
||||
TagName: "v1.2.3",
|
||||
Name: "",
|
||||
Body: "",
|
||||
BodyProvided: true,
|
||||
Draft: true,
|
||||
Target: "",
|
||||
DiscussionCategory: "general",
|
||||
},
|
||||
wantParams: map[string]interface{}{
|
||||
"tag_name": "v1.2.3",
|
||||
"name": "",
|
||||
"body": "",
|
||||
"draft": true,
|
||||
"prerelease": false,
|
||||
"discussion_category_name": "general",
|
||||
},
|
||||
wantErr: "X Discussions not supported with draft releases",
|
||||
wantStdout: "",
|
||||
},
|
||||
{
|
||||
name: "publish after uploading files",
|
||||
isTTY: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue