rebase with trunk
This commit is contained in:
commit
7fd0634a24
8 changed files with 52 additions and 5 deletions
|
|
@ -29,7 +29,7 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
|
|||
cmd := &cobra.Command{
|
||||
Use: "delete {<id> | <url>}",
|
||||
Short: "Delete a gist",
|
||||
Args: cmdutil.MinimumArgs(1, "cannot delete: gist argument required"),
|
||||
Args: cmdutil.ExactArgs(1, "cannot delete: gist argument required"),
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
opts.Selector = args[0]
|
||||
if runF != nil {
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
|
|||
|
||||
cmd := &cobra.Command{
|
||||
Use: "edit {<id> | <url>}",
|
||||
Short: "Edit or add files in a gist",
|
||||
Args: cmdutil.MinimumArgs(1, "cannot edit: gist argument required"),
|
||||
Short: "Edit one of your gists",
|
||||
Args: cmdutil.ExactArgs(1, "cannot edit: gist argument required"),
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
opts.Selector = args[0]
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
|
|||
cmd := &cobra.Command{
|
||||
Use: "view {<id> | <url>}",
|
||||
Short: "View a gist",
|
||||
Args: cmdutil.MinimumArgs(1, "cannot view: gist argument required"),
|
||||
Args: cmdutil.ExactArgs(1, "cannot view: gist argument required"),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.Selector = args[0]
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func NewCmdCheckout(f *cmdutil.Factory, runF func(*CheckoutOptions) error) *cobr
|
|||
cmd := &cobra.Command{
|
||||
Use: "checkout {<number> | <url> | <branch>}",
|
||||
Short: "Check out a pull request in git",
|
||||
Args: cmdutil.MinimumArgs(1, "argument required"),
|
||||
Args: cmdutil.ExactArgs(1, "argument required"),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// support `-R, --repo` override
|
||||
opts.BaseRepo = f.BaseRepo
|
||||
|
|
|
|||
|
|
@ -70,6 +70,9 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
|
|||
if flags.Changed("body") {
|
||||
opts.Editable.Body.Edited = true
|
||||
}
|
||||
if flags.Changed("base") {
|
||||
opts.Editable.Base.Edited = true
|
||||
}
|
||||
if flags.Changed("add-reviewer") || flags.Changed("remove-reviewer") {
|
||||
opts.Editable.Reviewers.Edited = true
|
||||
}
|
||||
|
|
@ -104,6 +107,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
|
|||
|
||||
cmd.Flags().StringVarP(&opts.Editable.Title.Value, "title", "t", "", "Set the new title.")
|
||||
cmd.Flags().StringVarP(&opts.Editable.Body.Value, "body", "b", "", "Set the new body.")
|
||||
cmd.Flags().StringVarP(&opts.Editable.Base.Value, "base", "B", "", "Change the base `branch` for this pull request")
|
||||
cmd.Flags().StringSliceVar(&opts.Editable.Reviewers.Add, "add-reviewer", nil, "Add reviewers by their `login`.")
|
||||
cmd.Flags().StringSliceVar(&opts.Editable.Reviewers.Remove, "remove-reviewer", nil, "Remove reviewers by their `login`.")
|
||||
cmd.Flags().StringSliceVar(&opts.Editable.Assignees.Add, "add-assignee", nil, "Add assigned users by their `login`. Use \"@me\" to assign yourself.")
|
||||
|
|
@ -133,6 +137,7 @@ func editRun(opts *EditOptions) error {
|
|||
editable.Reviewers.Allowed = true
|
||||
editable.Title.Default = pr.Title
|
||||
editable.Body.Default = pr.Body
|
||||
editable.Base.Default = pr.BaseRefName
|
||||
editable.Reviewers.Default = pr.ReviewRequests.Logins()
|
||||
editable.Assignees.Default = pr.Assignees.Logins()
|
||||
editable.Labels.Default = pr.Labels.Names()
|
||||
|
|
@ -203,6 +208,9 @@ func updatePullRequest(client *api.Client, repo ghrepo.Interface, id string, edi
|
|||
return err
|
||||
}
|
||||
params.MilestoneID = ghId(milestoneId)
|
||||
if editable.Base.Edited {
|
||||
params.BaseRefName = ghString(&editable.Base.Value)
|
||||
}
|
||||
err = api.UpdatePullRequest(client, repo, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -65,6 +65,20 @@ func TestNewCmdEdit(t *testing.T) {
|
|||
},
|
||||
wantsErr: false,
|
||||
},
|
||||
{
|
||||
name: "base flag",
|
||||
input: "23 --base base-branch-name",
|
||||
output: EditOptions{
|
||||
SelectorArg: "23",
|
||||
Editable: shared.Editable{
|
||||
Base: shared.EditableString{
|
||||
Value: "base-branch-name",
|
||||
Edited: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
wantsErr: false,
|
||||
},
|
||||
{
|
||||
name: "add-reviewer flag",
|
||||
input: "23 --add-reviewer monalisa,owner/core",
|
||||
|
|
@ -254,6 +268,10 @@ func Test_editRun(t *testing.T) {
|
|||
Value: "new body",
|
||||
Edited: true,
|
||||
},
|
||||
Base: shared.EditableString{
|
||||
Value: "base-branch-name",
|
||||
Edited: true,
|
||||
},
|
||||
Reviewers: shared.EditableSlice{
|
||||
Add: []string{"OWNER/core", "OWNER/external", "monalisa", "hubot"},
|
||||
Remove: []string{"dependabot"},
|
||||
|
|
@ -303,6 +321,10 @@ func Test_editRun(t *testing.T) {
|
|||
Value: "new body",
|
||||
Edited: true,
|
||||
},
|
||||
Base: shared.EditableString{
|
||||
Value: "base-branch-name",
|
||||
Edited: true,
|
||||
},
|
||||
Assignees: shared.EditableSlice{
|
||||
Add: []string{"monalisa", "hubot"},
|
||||
Remove: []string{"octocat"},
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
type Editable struct {
|
||||
Title EditableString
|
||||
Body EditableString
|
||||
Base EditableString
|
||||
Reviewers EditableSlice
|
||||
Assignees EditableSlice
|
||||
Labels EditableSlice
|
||||
|
|
@ -42,6 +43,7 @@ type EditableSlice struct {
|
|||
func (e Editable) Dirty() bool {
|
||||
return e.Title.Edited ||
|
||||
e.Body.Edited ||
|
||||
e.Base.Edited ||
|
||||
e.Reviewers.Edited ||
|
||||
e.Assignees.Edited ||
|
||||
e.Labels.Edited ||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,21 @@ func MinimumArgs(n int, msg string) cobra.PositionalArgs {
|
|||
}
|
||||
}
|
||||
|
||||
func ExactArgs(n int, msg string) cobra.PositionalArgs {
|
||||
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) > n {
|
||||
return &FlagError{Err: errors.New("too many arguments")}
|
||||
}
|
||||
|
||||
if len(args) < n {
|
||||
return &FlagError{Err: errors.New(msg)}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func NoArgsQuoteReminder(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 1 {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue