aboutsummaryrefslogtreecommitdiffstats
path: root/entities
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2024-08-25 20:40:23 +0200
committerGitHub <noreply@github.com>2024-08-25 18:40:23 +0000
commit3a4b8805dfd794cc25f57e99c73ddec651805af1 (patch)
treeb6af67c761c96b323400d061db22ceed73fb0bb0 /entities
parentc3ff05f95bdfad6c2ea4cb899024fd47ac503b5f (diff)
downloadgit-bug-3a4b8805dfd794cc25f57e99c73ddec651805af1.tar.gz
core: make label a common type, in a similar fashion as for status (#1252)
This will be useful for Board, and likely code review support later
Diffstat (limited to 'entities')
-rw-r--r--entities/bug/op_label_change.go29
-rw-r--r--entities/bug/op_label_change_test.go7
-rw-r--r--entities/bug/operation_test.go6
-rw-r--r--entities/bug/snapshot.go2
-rw-r--r--entities/common/label.go (renamed from entities/bug/label.go)2
-rw-r--r--entities/common/label_test.go (renamed from entities/bug/label_test.go)2
6 files changed, 25 insertions, 23 deletions
diff --git a/entities/bug/op_label_change.go b/entities/bug/op_label_change.go
index b65b8ffb..6a9fb19b 100644
--- a/entities/bug/op_label_change.go
+++ b/entities/bug/op_label_change.go
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
+ "github.com/git-bug/git-bug/entities/common"
"github.com/git-bug/git-bug/entities/identity"
"github.com/git-bug/git-bug/entity"
"github.com/git-bug/git-bug/entity/dag"
@@ -19,8 +20,8 @@ var _ Operation = &LabelChangeOperation{}
// LabelChangeOperation define a Bug operation to add or remove labels
type LabelChangeOperation struct {
dag.OpBase
- Added []Label `json:"added"`
- Removed []Label `json:"removed"`
+ Added []common.Label `json:"added"`
+ Removed []common.Label `json:"removed"`
}
func (op *LabelChangeOperation) Id() entity.Id {
@@ -96,7 +97,7 @@ func (op *LabelChangeOperation) Validate() error {
return nil
}
-func NewLabelChangeOperation(author identity.Interface, unixTime int64, added, removed []Label) *LabelChangeOperation {
+func NewLabelChangeOperation(author identity.Interface, unixTime int64, added, removed []common.Label) *LabelChangeOperation {
return &LabelChangeOperation{
OpBase: dag.NewOpBase(LabelChangeOp, author, unixTime),
Added: added,
@@ -108,8 +109,8 @@ type LabelChangeTimelineItem struct {
combinedId entity.CombinedId
Author identity.Interface
UnixTime timestamp.Timestamp
- Added []Label
- Removed []Label
+ Added []common.Label
+ Removed []common.Label
}
func (l LabelChangeTimelineItem) CombinedId() entity.CombinedId {
@@ -121,13 +122,13 @@ func (l *LabelChangeTimelineItem) IsAuthored() {}
// ChangeLabels is a convenience function to change labels on a bug
func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) ([]LabelChangeResult, *LabelChangeOperation, error) {
- var added, removed []Label
+ var added, removed []common.Label
var results []LabelChangeResult
snap := b.Compile()
for _, str := range add {
- label := Label(str)
+ label := common.Label(str)
// check for duplicate
if labelExist(added, label) {
@@ -146,7 +147,7 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r
}
for _, str := range remove {
- label := Label(str)
+ label := common.Label(str)
// check for duplicate
if labelExist(removed, label) {
@@ -187,14 +188,14 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r
// The intended use of this function is to allow importers to create legal but unexpected label changes,
// like removing a label with no information of when it was added before.
func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) (*LabelChangeOperation, error) {
- added := make([]Label, len(add))
+ added := make([]common.Label, len(add))
for i, str := range add {
- added[i] = Label(str)
+ added[i] = common.Label(str)
}
- removed := make([]Label, len(remove))
+ removed := make([]common.Label, len(remove))
for i, str := range remove {
- removed[i] = Label(str)
+ removed[i] = common.Label(str)
}
op := NewLabelChangeOperation(author, unixTime, added, removed)
@@ -211,7 +212,7 @@ func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, a
return op, nil
}
-func labelExist(labels []Label, label Label) bool {
+func labelExist(labels []common.Label, label common.Label) bool {
for _, l := range labels {
if l == label {
return true
@@ -272,7 +273,7 @@ func (l *LabelChangeStatus) UnmarshalGQL(v interface{}) error {
}
type LabelChangeResult struct {
- Label Label
+ Label common.Label
Status LabelChangeStatus
}
diff --git a/entities/bug/op_label_change_test.go b/entities/bug/op_label_change_test.go
index d184e47a..abafa222 100644
--- a/entities/bug/op_label_change_test.go
+++ b/entities/bug/op_label_change_test.go
@@ -3,6 +3,7 @@ package bug
import (
"testing"
+ "github.com/git-bug/git-bug/entities/common"
"github.com/git-bug/git-bug/entities/identity"
"github.com/git-bug/git-bug/entity"
"github.com/git-bug/git-bug/entity/dag"
@@ -10,12 +11,12 @@ import (
func TestLabelChangeSerialize(t *testing.T) {
dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) {
- return NewLabelChangeOperation(author, unixTime, []Label{"added"}, []Label{"removed"}), nil
+ return NewLabelChangeOperation(author, unixTime, []common.Label{"added"}, []common.Label{"removed"}), nil
})
dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) {
- return NewLabelChangeOperation(author, unixTime, []Label{"added"}, nil), nil
+ return NewLabelChangeOperation(author, unixTime, []common.Label{"added"}, nil), nil
})
dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) {
- return NewLabelChangeOperation(author, unixTime, nil, []Label{"removed"}), nil
+ return NewLabelChangeOperation(author, unixTime, nil, []common.Label{"removed"}), nil
})
}
diff --git a/entities/bug/operation_test.go b/entities/bug/operation_test.go
index d24faa7a..a6f122b3 100644
--- a/entities/bug/operation_test.go
+++ b/entities/bug/operation_test.go
@@ -32,7 +32,7 @@ func TestValidate(t *testing.T) {
NewSetTitleOp(rene, unix, "title2", "title1"),
NewAddCommentOp(rene, unix, "message2", nil),
NewSetStatusOp(rene, unix, common.ClosedStatus),
- NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"}),
+ NewLabelChangeOperation(rene, unix, []common.Label{"added"}, []common.Label{"removed"}),
}
for _, op := range good {
@@ -65,8 +65,8 @@ func TestValidate(t *testing.T) {
NewAddCommentOp(rene, unix, "message", []repository.Hash{repository.Hash("invalid")}),
NewSetStatusOp(rene, unix, 1000),
NewSetStatusOp(rene, unix, 0),
- NewLabelChangeOperation(rene, unix, []Label{}, []Label{}),
- NewLabelChangeOperation(rene, unix, []Label{"multi\nline"}, []Label{}),
+ NewLabelChangeOperation(rene, unix, []common.Label{}, []common.Label{}),
+ NewLabelChangeOperation(rene, unix, []common.Label{"multi\nline"}, []common.Label{}),
}
for i, op := range bad {
diff --git a/entities/bug/snapshot.go b/entities/bug/snapshot.go
index ca352284..7f9e7e58 100644
--- a/entities/bug/snapshot.go
+++ b/entities/bug/snapshot.go
@@ -19,7 +19,7 @@ type Snapshot struct {
Status common.Status
Title string
Comments []Comment
- Labels []Label
+ Labels []common.Label
Author identity.Interface
Actors []identity.Interface
Participants []identity.Interface
diff --git a/entities/bug/label.go b/entities/common/label.go
index 948a5b47..92d6c242 100644
--- a/entities/bug/label.go
+++ b/entities/common/label.go
@@ -1,4 +1,4 @@
-package bug
+package common
import (
"crypto/sha256"
diff --git a/entities/bug/label_test.go b/entities/common/label_test.go
index 49401c49..206fc4ab 100644
--- a/entities/bug/label_test.go
+++ b/entities/common/label_test.go
@@ -1,4 +1,4 @@
-package bug
+package common
import (
"testing"