Rename gh pr update to gh pr update-branch

Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>
This commit is contained in:
Babak K. Shandiz 2024-07-17 18:45:57 +01:00
parent 989152e64f
commit b584895ad8
No known key found for this signature in database
GPG key ID: 44950AED81AD710F
3 changed files with 33 additions and 33 deletions

View file

@ -16,7 +16,7 @@ import (
cmdReopen "github.com/cli/cli/v2/pkg/cmd/pr/reopen"
cmdReview "github.com/cli/cli/v2/pkg/cmd/pr/review"
cmdStatus "github.com/cli/cli/v2/pkg/cmd/pr/status"
cmdUpdate "github.com/cli/cli/v2/pkg/cmd/pr/update"
cmdUpdateBranch "github.com/cli/cli/v2/pkg/cmd/pr/update"
cmdView "github.com/cli/cli/v2/pkg/cmd/pr/view"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/spf13/cobra"
@ -58,7 +58,7 @@ func NewCmdPR(f *cmdutil.Factory) *cobra.Command {
cmdChecks.NewCmdChecks(f, nil),
cmdReview.NewCmdReview(f, nil),
cmdMerge.NewCmdMerge(f, nil),
cmdUpdate.NewCmdUpdate(f, nil),
cmdUpdateBranch.NewCmdUpdateBranch(f, nil),
cmdReady.NewCmdReady(f, nil),
cmdComment.NewCmdComment(f, nil),
cmdClose.NewCmdClose(f, nil),

View file

@ -16,7 +16,7 @@ import (
"github.com/spf13/cobra"
)
type UpdateOptions struct {
type UpdateBranchOptions struct {
HttpClient func() (*http.Client, error)
IO *iostreams.IOStreams
GitClient *git.Client
@ -27,15 +27,15 @@ type UpdateOptions struct {
Rebase bool
}
func NewCmdUpdate(f *cmdutil.Factory, runF func(*UpdateOptions) error) *cobra.Command {
opts := &UpdateOptions{
func NewCmdUpdateBranch(f *cmdutil.Factory, runF func(*UpdateBranchOptions) error) *cobra.Command {
opts := &UpdateBranchOptions{
IO: f.IOStreams,
HttpClient: f.HttpClient,
GitClient: f.GitClient,
}
cmd := &cobra.Command{
Use: "update [<number> | <url> | <branch>]",
Use: "update-branch [<number> | <url> | <branch>]",
Short: "Update a pull request branch",
Long: heredoc.Docf(`
Update a pull request branch with latest changes of the base branch.
@ -47,9 +47,9 @@ func NewCmdUpdate(f *cmdutil.Factory, runF func(*UpdateOptions) error) *cobra.Co
branch, the %[1]s--rebase%[1]s option should be provided.
`, "`"),
Example: heredoc.Doc(`
$ gh pr update 23
$ gh pr update 23 --rebase
$ gh pr update 23 --repo owner/repo
$ gh pr update-branch 23
$ gh pr update-branch 23 --rebase
$ gh pr update-branch 23 --repo owner/repo
`),
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
@ -67,7 +67,7 @@ func NewCmdUpdate(f *cmdutil.Factory, runF func(*UpdateOptions) error) *cobra.Co
return runF(opts)
}
return updateRun(opts)
return updateBranchRun(opts)
},
}
@ -76,7 +76,7 @@ func NewCmdUpdate(f *cmdutil.Factory, runF func(*UpdateOptions) error) *cobra.Co
return cmd
}
func updateRun(opts *UpdateOptions) error {
func updateBranchRun(opts *UpdateBranchOptions) error {
findOptions := shared.FindOptions{
Selector: opts.SelectorArg,
Fields: []string{"id", "number", "headRefName", "headRefOid", "headRepositoryOwner", "mergeable"},

View file

@ -16,36 +16,36 @@ import (
"github.com/stretchr/testify/assert"
)
func TestNewCmdUpdate(t *testing.T) {
func TestNewCmdUpdateBranch(t *testing.T) {
tests := []struct {
name string
input string
output UpdateOptions
output UpdateBranchOptions
wantsErr string
}{
{
name: "no argument",
input: "",
output: UpdateOptions{},
output: UpdateBranchOptions{},
},
{
name: "with argument",
input: "23",
output: UpdateOptions{
output: UpdateBranchOptions{
SelectorArg: "23",
},
},
{
name: "no argument, --rebase",
input: "--rebase",
output: UpdateOptions{
output: UpdateBranchOptions{
Rebase: true,
},
},
{
name: "with argument, --rebase",
input: "23 --rebase",
output: UpdateOptions{
output: UpdateBranchOptions{
SelectorArg: "23",
Rebase: true,
},
@ -67,8 +67,8 @@ func TestNewCmdUpdate(t *testing.T) {
IOStreams: ios,
}
var gotOpts *UpdateOptions
cmd := NewCmdUpdate(f, func(opts *UpdateOptions) error {
var gotOpts *UpdateBranchOptions
cmd := NewCmdUpdateBranch(f, func(opts *UpdateBranchOptions) error {
gotOpts = opts
return nil
})
@ -96,9 +96,9 @@ func TestNewCmdUpdate(t *testing.T) {
}
}
func Test_updateRun(t *testing.T) {
defaultInput := func() UpdateOptions {
return UpdateOptions{
func Test_updateBranchRun(t *testing.T) {
defaultInput := func() UpdateBranchOptions {
return UpdateBranchOptions{
Finder: shared.NewMockFinder("123", &api.PullRequest{
ID: "123",
Number: 123,
@ -112,7 +112,7 @@ func Test_updateRun(t *testing.T) {
tests := []struct {
name string
input *UpdateOptions
input *UpdateBranchOptions
httpStubs func(*testing.T, *httpmock.Registry)
stdout string
stderr string
@ -120,7 +120,7 @@ func Test_updateRun(t *testing.T) {
}{
{
name: "failure, pr not found",
input: &UpdateOptions{
input: &UpdateBranchOptions{
Finder: shared.NewMockFinder("", nil, nil),
SelectorArg: "123",
},
@ -128,7 +128,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "success, already up-to-date",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
@ -157,7 +157,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "success, already up-to-date, PR branch on the same repo as base",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
Finder: shared.NewMockFinder("123", &api.PullRequest{
ID: "123",
@ -194,7 +194,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "failure, not mergeable due to conflicts",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
Finder: shared.NewMockFinder("123", &api.PullRequest{
ID: "123",
@ -210,7 +210,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "success, merge",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
@ -252,7 +252,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "success, rebase",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
Rebase: true,
},
@ -295,7 +295,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "failure, API error on ref comparison request",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
@ -317,7 +317,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "failure, merge conflict error on update request",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
@ -361,7 +361,7 @@ func Test_updateRun(t *testing.T) {
},
{
name: "failure, API error on update request",
input: &UpdateOptions{
input: &UpdateBranchOptions{
SelectorArg: "123",
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
@ -430,7 +430,7 @@ func Test_updateRun(t *testing.T) {
tt.input.IO = ios
tt.input.HttpClient = httpClient
err := updateRun(tt.input)
err := updateBranchRun(tt.input)
if tt.wantsErr != "" {
assert.EqualError(t, err, tt.wantsErr)