Skip to content

Commit

Permalink
Merge pull request #106 from zaquestion/create_noprompt
Browse files Browse the repository at this point in the history
[#105] (fix,mr,issue) editor was being skipped during create, due to default value introduced on a shared variable
  • Loading branch information
zaquestion authored Jan 19, 2018
2 parents c7fbbd3 + 42400be commit f9a5a8a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/issueCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -105,6 +109,6 @@ func issueText() (string, error) {
}

func init() {
issueCreateCmd.Flags().StringSliceVarP(&msgs, "message", "m", []string{}, "Use the given <msg>; multiple -m are concatenated as seperate paragraphs")
issueCreateCmd.Flags().StringSliceP("message", "m", []string{}, "Use the given <msg>; multiple -m are concatenated as seperate paragraphs")
issueCmd.AddCommand(issueCreateCmd)
}
6 changes: 5 additions & 1 deletion cmd/mrCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ var mrCreateCmd = &cobra.Command{
}

func init() {
mrCreateCmd.Flags().StringSliceVarP(&msgs, "message", "m", []string{}, "Use the given <msg>; multiple -m are concatenated as seperate paragraphs")
mrCreateCmd.Flags().StringSliceP("message", "m", []string{}, "Use the given <msg>; 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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
28 changes: 24 additions & 4 deletions cmd/mr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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

Expand Down
7 changes: 5 additions & 2 deletions cmd/snippetCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
)

var (
msgs []string
name string
file string
private bool
Expand All @@ -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])
Expand Down Expand Up @@ -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 <msg>; multiple -m are concatenated as seperate paragraphs")
snippetCreateCmd.Flags().StringSliceP("message", "m", []string{"-"}, "Use the given <msg>; multiple -m are concatenated as seperate paragraphs")
snippetCmd.Flags().AddFlagSet(snippetCreateCmd.Flags())
snippetCmd.AddCommand(snippetCreateCmd)
}
4 changes: 4 additions & 0 deletions cmd/snippetCreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f9a5a8a

Please sign in to comment.