diff options
Diffstat (limited to 'bug/operations')
-rw-r--r-- | bug/operations/add_comment.go | 5 | ||||
-rw-r--r-- | bug/operations/create.go | 8 | ||||
-rw-r--r-- | bug/operations/label_change.go | 64 | ||||
-rw-r--r-- | bug/operations/set_status.go | 10 | ||||
-rw-r--r-- | bug/operations/set_title.go | 5 |
5 files changed, 92 insertions, 0 deletions
diff --git a/bug/operations/add_comment.go b/bug/operations/add_comment.go index 9ee8dc64..66725915 100644 --- a/bug/operations/add_comment.go +++ b/bug/operations/add_comment.go @@ -31,3 +31,8 @@ func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { return snapshot } + +func Comment(b *bug.Bug, author bug.Person, message string) { + addCommentOp := NewAddCommentOp(author, message) + b.Append(addCommentOp) +} diff --git a/bug/operations/create.go b/bug/operations/create.go index 72eba843..0fd1225e 100644 --- a/bug/operations/create.go +++ b/bug/operations/create.go @@ -33,3 +33,11 @@ func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { } return snapshot } + +func Create(author bug.Person, title, message string) (*bug.Bug, error) { + newBug := bug.NewBug() + createOp := NewCreateOp(author, title, message) + newBug.Append(createOp) + + return newBug, nil +} diff --git a/bug/operations/label_change.go b/bug/operations/label_change.go index ca07f6f5..b9bf86c8 100644 --- a/bug/operations/label_change.go +++ b/bug/operations/label_change.go @@ -1,7 +1,9 @@ package operations import ( + "fmt" "github.com/MichaelMure/git-bug/bug" + "io" "sort" ) @@ -54,3 +56,65 @@ AddLoop: return snapshot } + +func ChangeLabels(out io.Writer, b *bug.Bug, author bug.Person, add, remove []string) error { + var added, removed []bug.Label + + snap := b.Compile() + + for _, str := range add { + label := bug.Label(str) + + // check for duplicate + if labelExist(added, label) { + fmt.Fprintf(out, "label \"%s\" is a duplicate\n", str) + continue + } + + // check that the label doesn't already exist + if labelExist(snap.Labels, label) { + fmt.Fprintf(out, "label \"%s\" is already set on this bug\n", str) + continue + } + + added = append(added, label) + } + + for _, str := range remove { + label := bug.Label(str) + + // check for duplicate + if labelExist(removed, label) { + fmt.Fprintf(out, "label \"%s\" is a duplicate\n", str) + continue + } + + // check that the label actually exist + if !labelExist(snap.Labels, label) { + fmt.Fprintf(out, "label \"%s\" doesn't exist on this bug\n", str) + continue + } + + removed = append(removed, label) + } + + if len(added) == 0 && len(removed) == 0 { + return fmt.Errorf("no label added or removed") + } + + labelOp := NewLabelChangeOperation(author, added, removed) + + b.Append(labelOp) + + return nil +} + +func labelExist(labels []bug.Label, label bug.Label) bool { + for _, l := range labels { + if l == label { + return true + } + } + + return false +} diff --git a/bug/operations/set_status.go b/bug/operations/set_status.go index 7c718cd6..b62409dc 100644 --- a/bug/operations/set_status.go +++ b/bug/operations/set_status.go @@ -25,3 +25,13 @@ func (op SetStatusOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { return snapshot } + +func Open(b *bug.Bug, author bug.Person) { + op := NewSetStatusOp(author, bug.OpenStatus) + b.Append(op) +} + +func Close(b *bug.Bug, author bug.Person) { + op := NewSetStatusOp(author, bug.ClosedStatus) + b.Append(op) +} diff --git a/bug/operations/set_title.go b/bug/operations/set_title.go index ef934db1..295db282 100644 --- a/bug/operations/set_title.go +++ b/bug/operations/set_title.go @@ -25,3 +25,8 @@ func (op SetTitleOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { return snapshot } + +func SetTitle(b *bug.Bug, author bug.Person, title string) { + setTitleOp := NewSetTitleOp(author, title) + b.Append(setTitleOp) +} |