aboutsummaryrefslogtreecommitdiffstats
path: root/operations/label_change.go
diff options
context:
space:
mode:
Diffstat (limited to 'operations/label_change.go')
-rw-r--r--operations/label_change.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/operations/label_change.go b/operations/label_change.go
index a3cc9898..507651df 100644
--- a/operations/label_change.go
+++ b/operations/label_change.go
@@ -5,6 +5,7 @@ import (
"sort"
"github.com/MichaelMure/git-bug/bug"
+ "github.com/pkg/errors"
)
var _ bug.Operation = LabelChangeOperation{}
@@ -49,6 +50,30 @@ AddLoop:
return snapshot
}
+func (op LabelChangeOperation) Validate() error {
+ if err := bug.OpBaseValidate(op, bug.LabelChangeOp); err != nil {
+ return err
+ }
+
+ for _, l := range op.Added {
+ if err := l.Validate(); err != nil {
+ return errors.Wrap(err, "added label")
+ }
+ }
+
+ for _, l := range op.Removed {
+ if err := l.Validate(); err != nil {
+ return errors.Wrap(err, "removed label")
+ }
+ }
+
+ if len(op.Added)+len(op.Removed) <= 0 {
+ return fmt.Errorf("no label change")
+ }
+
+ return nil
+}
+
func NewLabelChangeOperation(author bug.Person, added, removed []bug.Label) LabelChangeOperation {
return LabelChangeOperation{
OpBase: bug.NewOpBase(bug.LabelChangeOp, author),
@@ -108,6 +133,10 @@ func ChangeLabels(b bug.Interface, author bug.Person, add, remove []string) ([]L
labelOp := NewLabelChangeOperation(author, added, removed)
+ if err := labelOp.Validate(); err != nil {
+ return nil, err
+ }
+
b.Append(labelOp)
return results, nil