aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-25 18:01:32 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-25 18:01:32 +0200
commit6a12373965aff9f80147f8b5bff6a5a104927365 (patch)
treeccc1e34fba059512acab39286a86f6b73c5ad318 /commands
parent49c90eab26875cbf3094d9a546ad29b426e174a1 (diff)
downloadgit-bug-6a12373965aff9f80147f8b5bff6a5a104927365.tar.gz
more refactoring to have reusable bug action across different UI
Diffstat (limited to 'commands')
-rw-r--r--commands/close.go8
-rw-r--r--commands/comment.go8
-rw-r--r--commands/label.go70
-rw-r--r--commands/new.go16
-rw-r--r--commands/open.go8
-rw-r--r--commands/pull.go22
6 files changed, 30 insertions, 102 deletions
diff --git a/commands/close.go b/commands/close.go
index 58446d71..f57519ea 100644
--- a/commands/close.go
+++ b/commands/close.go
@@ -28,13 +28,9 @@ func runCloseBug(cmd *cobra.Command, args []string) error {
return err
}
- op := operations.NewSetStatusOp(author, bug.ClosedStatus)
+ operations.Close(b, author)
- b.Append(op)
-
- err = b.Commit(repo)
-
- return err
+ return b.Commit(repo)
}
var closeCmd = &cobra.Command{
diff --git a/commands/comment.go b/commands/comment.go
index 252fb7e4..ebbeaa77 100644
--- a/commands/comment.go
+++ b/commands/comment.go
@@ -49,13 +49,9 @@ func runComment(cmd *cobra.Command, args []string) error {
return err
}
- addCommentOp := operations.NewAddCommentOp(author, commentMessage)
+ operations.Comment(b, author, commentMessage)
- b.Append(addCommentOp)
-
- err = b.Commit(repo)
-
- return err
+ return b.Commit(repo)
}
var commentCmd = &cobra.Command{
diff --git a/commands/label.go b/commands/label.go
index e1679972..ee6ed25f 100644
--- a/commands/label.go
+++ b/commands/label.go
@@ -2,10 +2,10 @@ package commands
import (
"errors"
- "fmt"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/bug/operations"
"github.com/spf13/cobra"
+ "os"
)
var labelRemove bool
@@ -21,6 +21,14 @@ func runLabel(cmd *cobra.Command, args []string) error {
prefix := args[0]
+ var add, remove []string
+
+ if labelRemove {
+ remove = args[1:]
+ } else {
+ add = args[1:]
+ }
+
b, err := bug.FindLocalBug(repo, prefix)
if err != nil {
return err
@@ -31,65 +39,13 @@ func runLabel(cmd *cobra.Command, args []string) error {
return err
}
- var added, removed []bug.Label
-
- snap := b.Compile()
-
- for _, arg := range args[1:] {
- label := bug.Label(arg)
-
- if labelRemove {
- // check for duplicate
- if labelExist(removed, label) {
- fmt.Printf("label \"%s\" is a duplicate\n", arg)
- continue
- }
-
- // check that the label actually exist
- if !labelExist(snap.Labels, label) {
- fmt.Printf("label \"%s\" doesn't exist on this bug\n", arg)
- continue
- }
-
- removed = append(removed, label)
- } else {
- // check for duplicate
- if labelExist(added, label) {
- fmt.Printf("label \"%s\" is a duplicate\n", arg)
- continue
- }
-
- // check that the label doesn't already exist
- if labelExist(snap.Labels, label) {
- fmt.Printf("label \"%s\" is already set on this bug\n", arg)
- continue
- }
-
- added = append(added, label)
- }
- }
-
- if len(added) == 0 && len(removed) == 0 {
- return errors.New("no label added or removed")
- }
-
- labelOp := operations.NewLabelChangeOperation(author, added, removed)
-
- b.Append(labelOp)
+ err = operations.ChangeLabels(os.Stdout, b, author, add, remove)
- err = b.Commit(repo)
-
- return err
-}
-
-func labelExist(labels []bug.Label, label bug.Label) bool {
- for _, l := range labels {
- if l == label {
- return true
- }
+ if err != nil {
+ return err
}
- return false
+ return b.Commit(repo)
}
var labelCmd = &cobra.Command{
diff --git a/commands/new.go b/commands/new.go
index 9844e121..4168453e 100644
--- a/commands/new.go
+++ b/commands/new.go
@@ -44,18 +44,20 @@ func runNewBug(cmd *cobra.Command, args []string) error {
return err
}
- newBug := bug.NewBug()
-
- createOp := operations.NewCreateOp(author, title, newMessage)
-
- newBug.Append(createOp)
+ newBug, err := operations.Create(author, title, newMessage)
+ if err != nil {
+ return err
+ }
err = newBug.Commit(repo)
- fmt.Printf("%s created\n", newBug.HumanId())
+ if err != nil {
+ return err
+ }
- return err
+ fmt.Printf("%s created\n", newBug.HumanId())
+ return nil
}
var newCmd = &cobra.Command{
diff --git a/commands/open.go b/commands/open.go
index 7fa59b49..c99578cf 100644
--- a/commands/open.go
+++ b/commands/open.go
@@ -28,13 +28,9 @@ func runOpenBug(cmd *cobra.Command, args []string) error {
return err
}
- op := operations.NewSetStatusOp(author, bug.OpenStatus)
+ operations.Open(b, author)
- b.Append(op)
-
- err = b.Commit(repo)
-
- return err
+ return b.Commit(repo)
}
var openCmd = &cobra.Command{
diff --git a/commands/pull.go b/commands/pull.go
index ac6a3732..52b3ecd8 100644
--- a/commands/pull.go
+++ b/commands/pull.go
@@ -2,9 +2,9 @@ package commands
import (
"errors"
- "fmt"
"github.com/MichaelMure/git-bug/bug"
"github.com/spf13/cobra"
+ "os"
)
func runPull(cmd *cobra.Command, args []string) error {
@@ -17,25 +17,7 @@ func runPull(cmd *cobra.Command, args []string) error {
remote = args[0]
}
- fmt.Printf("Fetching remote ...\n\n")
-
- if err := bug.Fetch(repo, remote); err != nil {
- return err
- }
-
- fmt.Printf("\nMerging data ...\n\n")
-
- for merge := range bug.MergeAll(repo, remote) {
- if merge.Err != nil {
- return merge.Err
- }
-
- if merge.Status != bug.MsgNothing {
- fmt.Printf("%s: %s\n", merge.HumanId, merge.Status)
- }
- }
-
- return nil
+ return bug.Pull(repo, os.Stdout, remote)
}
// showCmd defines the "push" subcommand.