MCPcopy Create free account
hub / github.com/cli/cli / NewCmdMerge

Function NewCmdMerge

pkg/cmd/pr/merge/merge.go:60–187  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*MergeOptions) error)

Source from the content-addressed store, hash-verified

58var ErrAlreadyInMergeQueue = errors.New("already in merge queue")
59
60func NewCmdMerge(f *cmdutil.Factory, runF func(*MergeOptions) error) *cobra.Command {
61 opts := &MergeOptions{
62 IO: f.IOStreams,
63 HttpClient: f.HttpClient,
64 GitClient: f.GitClient,
65 Branch: f.Branch,
66 Remotes: f.Remotes,
67 Prompter: f.Prompter,
68 }
69
70 var (
71 flagMerge bool
72 flagSquash bool
73 flagRebase bool
74 )
75
76 var bodyFile string
77
78 cmd := &cobra.Command{
79 Use: "merge [<number> | <url> | <branch>]",
80 Short: "Merge a pull request",
81 Long: heredoc.Docf(`
82 Merge a pull request on GitHub.
83
84 Without an argument, the pull request that belongs to the current branch
85 is selected.
86
87 When targeting a branch that requires a merge queue, no merge strategy is required.
88 If required checks have not yet passed, auto-merge will be enabled.
89 If required checks have passed, the pull request will be added to the merge queue.
90 To bypass a merge queue and merge directly, pass the %[1]s--admin%[1]s flag.
91 `, "`"),
92 Args: cobra.MaximumNArgs(1),
93 RunE: func(cmd *cobra.Command, args []string) error {
94 opts.Finder = shared.NewFinder(f)
95
96 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
97 return cmdutil.FlagErrorf("argument required when using the --repo flag")
98 }
99
100 if len(args) > 0 {
101 opts.SelectorArg = args[0]
102 }
103
104 methodFlags := 0
105 if flagMerge {
106 opts.MergeMethod = PullRequestMergeMethodMerge
107 methodFlags++
108 }
109 if flagRebase {
110 opts.MergeMethod = PullRequestMergeMethodRebase
111 methodFlags++
112 }
113 if flagSquash {
114 opts.MergeMethod = PullRequestMergeMethodSquash
115 methodFlags++
116 }
117 if methodFlags == 0 {

Callers 2

Test_NewCmdMergeFunction · 0.85
runCommandWithBranchFuncFunction · 0.85

Calls 6

NewFinderFunction · 0.92
FlagErrorfFunction · 0.92
MutuallyExclusiveFunction · 0.92
ReadFileFunction · 0.92
mergeRunFunction · 0.85
ChangedMethod · 0.80

Tested by 2

Test_NewCmdMergeFunction · 0.68
runCommandWithBranchFuncFunction · 0.68