Skip to content

Commit 7fd0634

Browse files
committed
rebase with trunk
2 parents 3e5d5a2 + e4ce0d7 commit 7fd0634

File tree

8 files changed

+52
-5
lines changed

8 files changed

+52
-5
lines changed

pkg/cmd/gist/delete/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
2929
cmd := &cobra.Command{
3030
Use: "delete {<id> | <url>}",
3131
Short: "Delete a gist",
32-
Args: cmdutil.MinimumArgs(1, "cannot delete: gist argument required"),
32+
Args: cmdutil.ExactArgs(1, "cannot delete: gist argument required"),
3333
RunE: func(c *cobra.Command, args []string) error {
3434
opts.Selector = args[0]
3535
if runF != nil {

pkg/cmd/gist/edit/edit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
5050

5151
cmd := &cobra.Command{
5252
Use: "edit {<id> | <url>}",
53-
Short: "Edit or add files in a gist",
54-
Args: cmdutil.MinimumArgs(1, "cannot edit: gist argument required"),
53+
Short: "Edit one of your gists",
54+
Args: cmdutil.ExactArgs(1, "cannot edit: gist argument required"),
5555
RunE: func(c *cobra.Command, args []string) error {
5656
opts.Selector = args[0]
5757

pkg/cmd/gist/view/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
3535
cmd := &cobra.Command{
3636
Use: "view {<id> | <url>}",
3737
Short: "View a gist",
38-
Args: cmdutil.MinimumArgs(1, "cannot view: gist argument required"),
38+
Args: cmdutil.ExactArgs(1, "cannot view: gist argument required"),
3939
RunE: func(cmd *cobra.Command, args []string) error {
4040
opts.Selector = args[0]
4141

pkg/cmd/pr/checkout/checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewCmdCheckout(f *cmdutil.Factory, runF func(*CheckoutOptions) error) *cobr
4646
cmd := &cobra.Command{
4747
Use: "checkout {<number> | <url> | <branch>}",
4848
Short: "Check out a pull request in git",
49-
Args: cmdutil.MinimumArgs(1, "argument required"),
49+
Args: cmdutil.ExactArgs(1, "argument required"),
5050
RunE: func(cmd *cobra.Command, args []string) error {
5151
// support `-R, --repo` override
5252
opts.BaseRepo = f.BaseRepo

pkg/cmd/pr/edit/edit.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
7070
if flags.Changed("body") {
7171
opts.Editable.Body.Edited = true
7272
}
73+
if flags.Changed("base") {
74+
opts.Editable.Base.Edited = true
75+
}
7376
if flags.Changed("add-reviewer") || flags.Changed("remove-reviewer") {
7477
opts.Editable.Reviewers.Edited = true
7578
}
@@ -104,6 +107,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
104107

105108
cmd.Flags().StringVarP(&opts.Editable.Title.Value, "title", "t", "", "Set the new title.")
106109
cmd.Flags().StringVarP(&opts.Editable.Body.Value, "body", "b", "", "Set the new body.")
110+
cmd.Flags().StringVarP(&opts.Editable.Base.Value, "base", "B", "", "Change the base `branch` for this pull request")
107111
cmd.Flags().StringSliceVar(&opts.Editable.Reviewers.Add, "add-reviewer", nil, "Add reviewers by their `login`.")
108112
cmd.Flags().StringSliceVar(&opts.Editable.Reviewers.Remove, "remove-reviewer", nil, "Remove reviewers by their `login`.")
109113
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 {
133137
editable.Reviewers.Allowed = true
134138
editable.Title.Default = pr.Title
135139
editable.Body.Default = pr.Body
140+
editable.Base.Default = pr.BaseRefName
136141
editable.Reviewers.Default = pr.ReviewRequests.Logins()
137142
editable.Assignees.Default = pr.Assignees.Logins()
138143
editable.Labels.Default = pr.Labels.Names()
@@ -203,6 +208,9 @@ func updatePullRequest(client *api.Client, repo ghrepo.Interface, id string, edi
203208
return err
204209
}
205210
params.MilestoneID = ghId(milestoneId)
211+
if editable.Base.Edited {
212+
params.BaseRefName = ghString(&editable.Base.Value)
213+
}
206214
err = api.UpdatePullRequest(client, repo, params)
207215
if err != nil {
208216
return err

pkg/cmd/pr/edit/edit_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ func TestNewCmdEdit(t *testing.T) {
6565
},
6666
wantsErr: false,
6767
},
68+
{
69+
name: "base flag",
70+
input: "23 --base base-branch-name",
71+
output: EditOptions{
72+
SelectorArg: "23",
73+
Editable: shared.Editable{
74+
Base: shared.EditableString{
75+
Value: "base-branch-name",
76+
Edited: true,
77+
},
78+
},
79+
},
80+
wantsErr: false,
81+
},
6882
{
6983
name: "add-reviewer flag",
7084
input: "23 --add-reviewer monalisa,owner/core",
@@ -254,6 +268,10 @@ func Test_editRun(t *testing.T) {
254268
Value: "new body",
255269
Edited: true,
256270
},
271+
Base: shared.EditableString{
272+
Value: "base-branch-name",
273+
Edited: true,
274+
},
257275
Reviewers: shared.EditableSlice{
258276
Add: []string{"OWNER/core", "OWNER/external", "monalisa", "hubot"},
259277
Remove: []string{"dependabot"},
@@ -303,6 +321,10 @@ func Test_editRun(t *testing.T) {
303321
Value: "new body",
304322
Edited: true,
305323
},
324+
Base: shared.EditableString{
325+
Value: "base-branch-name",
326+
Edited: true,
327+
},
306328
Assignees: shared.EditableSlice{
307329
Add: []string{"monalisa", "hubot"},
308330
Remove: []string{"octocat"},

pkg/cmd/pr/shared/editable.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type Editable struct {
1515
Title EditableString
1616
Body EditableString
17+
Base EditableString
1718
Reviewers EditableSlice
1819
Assignees EditableSlice
1920
Labels EditableSlice
@@ -42,6 +43,7 @@ type EditableSlice struct {
4243
func (e Editable) Dirty() bool {
4344
return e.Title.Edited ||
4445
e.Body.Edited ||
46+
e.Base.Edited ||
4547
e.Reviewers.Edited ||
4648
e.Assignees.Edited ||
4749
e.Labels.Edited ||

pkg/cmdutil/args.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ func MinimumArgs(n int, msg string) cobra.PositionalArgs {
2121
}
2222
}
2323

24+
func ExactArgs(n int, msg string) cobra.PositionalArgs {
25+
26+
return func(cmd *cobra.Command, args []string) error {
27+
if len(args) > n {
28+
return &FlagError{Err: errors.New("too many arguments")}
29+
}
30+
31+
if len(args) < n {
32+
return &FlagError{Err: errors.New(msg)}
33+
}
34+
35+
return nil
36+
}
37+
}
38+
2439
func NoArgsQuoteReminder(cmd *cobra.Command, args []string) error {
2540
if len(args) < 1 {
2641
return nil

0 commit comments

Comments
 (0)