Skip to content

Commit 4e2898c

Browse files
committed
cmd/mr_create.go: Rearrange code
Rearrange code to match that of other files. There are no functionality changes introduced in this commit. Signed-off-by: Prarit Bhargava <prarit@redhat.com>
1 parent 1282241 commit 4e2898c

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

cmd/mr_create.go

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,6 @@ import (
1919
lab "github.com/zaquestion/lab/internal/gitlab"
2020
)
2121

22-
// mrCmd represents the mr command
23-
var mrCreateCmd = &cobra.Command{
24-
Use: "create [target_remote [target_branch]]",
25-
Aliases: []string{"new"},
26-
Short: "Creates a merge request.",
27-
Args: cobra.MaximumNArgs(2),
28-
Example: heredoc.Doc(`
29-
lab mr create target_remote
30-
lab mr create target_remote target_branch --allow-collaboration
31-
lab mr create upstream main --source my_fork:feature-3
32-
lab mr create a_remote -a johndoe -a janedoe
33-
lab mr create my_remote -c
34-
lab mr create my_remote --draft
35-
lab mr create my_remote -F a_file.txt
36-
lab mr create my_remote -F a_file.txt --force-linebreak
37-
lab mr create my_remote -f a_file.txt
38-
lab mr create my_remote -l bug -l confirmed
39-
lab mr create my_remote -m "A title message"
40-
lab mr create my_remote -m "A MR title" -m "A MR description"
41-
lab mr create my_remote --milestone "Fall"
42-
lab mr create my_remote -d
43-
lab mr create my_remote -r johndoe -r janedoe
44-
lab mr create my_remote -s`),
45-
PersistentPreRun: labPersistentPreRun,
46-
Run: runMRCreate,
47-
}
48-
49-
func init() {
50-
mrCreateCmd.Flags().StringArrayP("message", "m", []string{}, "use the given <msg>; multiple -m are concatenated as separate paragraphs")
51-
mrCreateCmd.Flags().StringSliceP("assignee", "a", []string{}, "set assignee by username; can be specified multiple times for multiple assignees")
52-
mrCreateCmd.Flags().StringSliceP("reviewer", "r", []string{}, "set reviewer by username; can be specified multiple times for multiple reviewers")
53-
mrCreateCmd.Flags().StringSliceP("label", "l", []string{}, "add label <label>; can be specified multiple times for multiple labels")
54-
mrCreateCmd.Flags().BoolP("remove-source-branch", "d", false, "remove source branch from remote after merge")
55-
mrCreateCmd.Flags().BoolP("squash", "s", false, "squash commits when merging")
56-
mrCreateCmd.Flags().Bool("allow-collaboration", false, "allow commits from other members")
57-
mrCreateCmd.Flags().String("milestone", "", "set milestone by milestone title or ID")
58-
mrCreateCmd.Flags().StringP("file", "F", "", "use the given file as the Title and Description")
59-
mrCreateCmd.Flags().StringP("file-edit", "f", "", "use the given file as the Title and Description and open the editor")
60-
mrCreateCmd.Flags().Bool("no-edit", false, "use the selected commit message without opening the editor")
61-
mrCreateCmd.Flags().Bool("force-linebreak", false, "append 2 spaces to the end of each line to force markdown linebreaks")
62-
mrCreateCmd.Flags().BoolP("cover-letter", "c", false, "comment changelog and diffstat")
63-
mrCreateCmd.Flags().Bool("draft", false, "mark the merge request as draft")
64-
mrCreateCmd.Flags().String("source", "", "specify the source remote and branch in the form of remote:branch")
65-
mergeRequestCmd.Flags().AddFlagSet(mrCreateCmd.Flags())
66-
67-
mrCmd.AddCommand(mrCreateCmd)
68-
69-
carapace.Gen(mrCreateCmd).FlagCompletion(carapace.ActionMap{
70-
"label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
71-
project, _, err := parseArgsRemoteAndProject(c.Args)
72-
if err != nil {
73-
return carapace.ActionMessage(err.Error())
74-
}
75-
return action.Labels(project).Invoke(c).Filter(c.Parts).ToA()
76-
}),
77-
"milestone": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
78-
project, _, err := parseArgsRemoteAndProject(c.Args)
79-
if err != nil {
80-
return carapace.ActionMessage(err.Error())
81-
}
82-
return action.Milestones(project, action.MilestoneOpts{Active: true})
83-
}),
84-
})
85-
86-
carapace.Gen(mrCreateCmd).PositionalCompletion(
87-
action.Remotes(),
88-
action.RemoteBranches(0),
89-
)
90-
}
91-
9222
func verifyRemoteBranch(projID string, branch string) error {
9323
if _, err := lab.GetCommit(projID, branch); err != nil {
9424
return fmt.Errorf("%s is not a valid reference", branch)
@@ -444,3 +374,73 @@ func mrText(sourceRemote, sourceBranch, targetRemote, targetBranch string, cover
444374

445375
return b.String(), nil
446376
}
377+
378+
// mrCmd represents the mr command
379+
var mrCreateCmd = &cobra.Command{
380+
Use: "create [target_remote [target_branch]]",
381+
Aliases: []string{"new"},
382+
Short: "Creates a merge request.",
383+
Args: cobra.MaximumNArgs(2),
384+
Example: heredoc.Doc(`
385+
lab mr create target_remote
386+
lab mr create target_remote target_branch --allow-collaboration
387+
lab mr create upstream main --source my_fork:feature-3
388+
lab mr create a_remote -a johndoe -a janedoe
389+
lab mr create my_remote -c
390+
lab mr create my_remote --draft
391+
lab mr create my_remote -F a_file.txt
392+
lab mr create my_remote -F a_file.txt --force-linebreak
393+
lab mr create my_remote -f a_file.txt
394+
lab mr create my_remote -l bug -l confirmed
395+
lab mr create my_remote -m "A title message"
396+
lab mr create my_remote -m "A MR title" -m "A MR description"
397+
lab mr create my_remote --milestone "Fall"
398+
lab mr create my_remote -d
399+
lab mr create my_remote -r johndoe -r janedoe
400+
lab mr create my_remote -s`),
401+
PersistentPreRun: labPersistentPreRun,
402+
Run: runMRCreate,
403+
}
404+
405+
func init() {
406+
mrCreateCmd.Flags().StringArrayP("message", "m", []string{}, "use the given <msg>; multiple -m are concatenated as separate paragraphs")
407+
mrCreateCmd.Flags().StringSliceP("assignee", "a", []string{}, "set assignee by username; can be specified multiple times for multiple assignees")
408+
mrCreateCmd.Flags().StringSliceP("reviewer", "r", []string{}, "set reviewer by username; can be specified multiple times for multiple reviewers")
409+
mrCreateCmd.Flags().StringSliceP("label", "l", []string{}, "add label <label>; can be specified multiple times for multiple labels")
410+
mrCreateCmd.Flags().BoolP("remove-source-branch", "d", false, "remove source branch from remote after merge")
411+
mrCreateCmd.Flags().BoolP("squash", "s", false, "squash commits when merging")
412+
mrCreateCmd.Flags().Bool("allow-collaboration", false, "allow commits from other members")
413+
mrCreateCmd.Flags().String("milestone", "", "set milestone by milestone title or ID")
414+
mrCreateCmd.Flags().StringP("file", "F", "", "use the given file as the Title and Description")
415+
mrCreateCmd.Flags().StringP("file-edit", "f", "", "use the given file as the Title and Description and open the editor")
416+
mrCreateCmd.Flags().Bool("no-edit", false, "use the selected commit message without opening the editor")
417+
mrCreateCmd.Flags().Bool("force-linebreak", false, "append 2 spaces to the end of each line to force markdown linebreaks")
418+
mrCreateCmd.Flags().BoolP("cover-letter", "c", false, "comment changelog and diffstat")
419+
mrCreateCmd.Flags().Bool("draft", false, "mark the merge request as draft")
420+
mrCreateCmd.Flags().String("source", "", "specify the source remote and branch in the form of remote:branch")
421+
mergeRequestCmd.Flags().AddFlagSet(mrCreateCmd.Flags())
422+
423+
mrCmd.AddCommand(mrCreateCmd)
424+
425+
carapace.Gen(mrCreateCmd).FlagCompletion(carapace.ActionMap{
426+
"label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action {
427+
project, _, err := parseArgsRemoteAndProject(c.Args)
428+
if err != nil {
429+
return carapace.ActionMessage(err.Error())
430+
}
431+
return action.Labels(project).Invoke(c).Filter(c.Parts).ToA()
432+
}),
433+
"milestone": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
434+
project, _, err := parseArgsRemoteAndProject(c.Args)
435+
if err != nil {
436+
return carapace.ActionMessage(err.Error())
437+
}
438+
return action.Milestones(project, action.MilestoneOpts{Active: true})
439+
}),
440+
})
441+
442+
carapace.Gen(mrCreateCmd).PositionalCompletion(
443+
action.Remotes(),
444+
action.RemoteBranches(0),
445+
)
446+
}

0 commit comments

Comments
 (0)