diff --git a/cmd/issueCreate.go b/cmd/issueCreate.go index 1b5f1b26..96fd3d4d 100644 --- a/cmd/issueCreate.go +++ b/cmd/issueCreate.go @@ -21,6 +21,10 @@ var issueCreateCmd = &cobra.Command{ Long: ``, Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + msgs, err := cmd.Flags().GetStringSlice("message") + if err != nil { + log.Fatal(err) + } remote := forkedFromRemote if len(args) > 0 { ok, err := git.IsRemote(args[0]) @@ -105,6 +109,6 @@ func issueText() (string, error) { } func init() { - issueCreateCmd.Flags().StringSliceVarP(&msgs, "message", "m", []string{}, "Use the given ; multiple -m are concatenated as seperate paragraphs") + issueCreateCmd.Flags().StringSliceP("message", "m", []string{}, "Use the given ; multiple -m are concatenated as seperate paragraphs") issueCmd.AddCommand(issueCreateCmd) } diff --git a/cmd/mrCreate.go b/cmd/mrCreate.go index 0b5129ad..25528b62 100644 --- a/cmd/mrCreate.go +++ b/cmd/mrCreate.go @@ -34,11 +34,15 @@ var mrCreateCmd = &cobra.Command{ } func init() { - mrCreateCmd.Flags().StringSliceVarP(&msgs, "message", "m", []string{}, "Use the given ; multiple -m are concatenated as seperate paragraphs") + mrCreateCmd.Flags().StringSliceP("message", "m", []string{}, "Use the given ; multiple -m are concatenated as seperate paragraphs") mrCmd.AddCommand(mrCreateCmd) } func runMRCreate(cmd *cobra.Command, args []string) { + msgs, err := cmd.Flags().GetStringSlice("message") + if err != nil { + log.Fatal(err) + } branch, err := git.CurrentBranch() if err != nil { log.Fatal(err) diff --git a/cmd/mrList_test.go b/cmd/mrList_test.go index 477df142..461d7e18 100644 --- a/cmd/mrList_test.go +++ b/cmd/mrList_test.go @@ -69,5 +69,5 @@ func Test_mrListStateClosed(t *testing.T) { mrs := strings.Split(string(b), "\n") t.Log(mrs) - require.Equal(t, "#2 asdf", mrs[0]) + require.Equal(t, "#5 closed mr", mrs[0]) } diff --git a/cmd/mr_test.go b/cmd/mr_test.go index 6edcef7f..98b3a23d 100644 --- a/cmd/mr_test.go +++ b/cmd/mr_test.go @@ -11,10 +11,9 @@ import ( func Test_mrCmd(t *testing.T) { t.Parallel() + repo := copyTestRepo(t) var mrID string t.Run("create", func(t *testing.T) { - repo := copyTestRepo(t) - git := exec.Command("git", "checkout", "mrtest") git.Dir = repo b, err := git.CombinedOutput() @@ -24,7 +23,9 @@ func Test_mrCmd(t *testing.T) { } cmd := exec.Command("../lab_bin", "mr", "create", "lab-testing", - "-m", "mr title") + "-m", "mr title", + "-m", "mr description", + ) cmd.Dir = repo b, _ = cmd.CombinedOutput() @@ -36,11 +37,30 @@ func Test_mrCmd(t *testing.T) { mrID = strings.TrimPrefix(out[:i], "https://gitlab.com/lab-testing/test/merge_requests/") t.Log(mrID) }) + t.Run("show", func(t *testing.T) { + if mrID == "" { + t.Skip("mrID is empty, create likely failed") + } + cmd := exec.Command("../lab_bin", "mr", "show", "lab-testing", mrID) + cmd.Dir = repo + + b, err := cmd.CombinedOutput() + if err != nil { + t.Log(string(b)) + t.Fatal(err) + } + out := string(b) + require.Contains(t, out, "Project: lab-testing/test\n") + require.Contains(t, out, "Branches: mrtest->master\n") + require.Contains(t, out, "Status: Open\n") + require.Contains(t, out, fmt.Sprintf("#%s mr title", mrID)) + require.Contains(t, out, "===================================\nmr description") + require.Contains(t, out, fmt.Sprintf("WebURL: https://gitlab.com/lab-testing/test/merge_requests/%s", mrID)) + }) t.Run("delete", func(t *testing.T) { if mrID == "" { t.Skip("mrID is empty, create likely failed") } - repo := copyTestRepo(t) cmd := exec.Command("../lab_bin", "mr", "lab-testing", "-d", mrID) cmd.Dir = repo diff --git a/cmd/snippetCreate.go b/cmd/snippetCreate.go index 91d0c383..c1e33191 100644 --- a/cmd/snippetCreate.go +++ b/cmd/snippetCreate.go @@ -19,7 +19,6 @@ import ( ) var ( - msgs []string name string file string private bool @@ -34,6 +33,10 @@ var snippetCreateCmd = &cobra.Command{ Source snippets from stdin, file, or in editor from scratch Optionally add a title & description with -m`, Run: func(cmd *cobra.Command, args []string) { + msgs, err := cmd.Flags().GetStringSlice("message") + if err != nil { + log.Fatal(err) + } remote := forkedFromRemote if len(args) > 0 { ok, err := git.IsRemote(args[0]) @@ -166,7 +169,7 @@ func init() { snippetCreateCmd.Flags().BoolVarP(&private, "private", "p", false, "Make snippet private; visible only to project members (default: internal)") snippetCreateCmd.Flags().BoolVar(&public, "public", false, "Make snippet public; can be accessed without any authentication (default: internal)") snippetCreateCmd.Flags().StringVarP(&name, "name", "n", "", "(optional) Name snippet to add code highlighting, e.g. potato.go for GoLang") - snippetCreateCmd.Flags().StringSliceVarP(&msgs, "message", "m", []string{"-"}, "Use the given ; multiple -m are concatenated as seperate paragraphs") + snippetCreateCmd.Flags().StringSliceP("message", "m", []string{"-"}, "Use the given ; multiple -m are concatenated as seperate paragraphs") snippetCmd.Flags().AddFlagSet(snippetCreateCmd.Flags()) snippetCmd.AddCommand(snippetCreateCmd) } diff --git a/cmd/snippetCreate_test.go b/cmd/snippetCreate_test.go index b90267e9..53f42d38 100644 --- a/cmd/snippetCreate_test.go +++ b/cmd/snippetCreate_test.go @@ -146,6 +146,10 @@ func Test_snippetCreate_Global_Editor(t *testing.T) { } func Test_snipMsg(t *testing.T) { + msgs, err := snippetCreateCmd.Flags().GetStringSlice("message") + if err != nil { + t.Fatal(err) + } title, desc := snipMsg(msgs) assert.Equal(t, "-", title) assert.Equal(t, "", desc)