From 3a4b8805dfd794cc25f57e99c73ddec651805af1 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 25 Aug 2024 20:40:23 +0200 Subject: 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 --- commands/bug/bug.go | 3 +-- commands/bug/completion.go | 12 ++++++------ commands/cmdjson/bug.go | 35 ++++++++++++++++++----------------- 3 files changed, 25 insertions(+), 25 deletions(-) (limited to 'commands') diff --git a/commands/bug/bug.go b/commands/bug/bug.go index 4cf18ab9..4e696a49 100644 --- a/commands/bug/bug.go +++ b/commands/bug/bug.go @@ -13,7 +13,6 @@ import ( "github.com/git-bug/git-bug/commands/cmdjson" "github.com/git-bug/git-bug/commands/completion" "github.com/git-bug/git-bug/commands/execenv" - "github.com/git-bug/git-bug/entities/bug" "github.com/git-bug/git-bug/entities/common" "github.com/git-bug/git-bug/entity" "github.com/git-bug/git-bug/query" @@ -280,7 +279,7 @@ func bugsPlainFormatter(env *execenv.Env, excerpts []*cache.BugExcerpt) error { func bugsOrgmodeFormatter(env *execenv.Env, excerpts []*cache.BugExcerpt) error { // see https://orgmode.org/manual/Tags.html orgTagRe := regexp.MustCompile("[^[:alpha:]_@]") - formatTag := func(l bug.Label) string { + formatTag := func(l common.Label) string { return orgTagRe.ReplaceAllString(l.String(), "_") } diff --git a/commands/bug/completion.go b/commands/bug/completion.go index d313ef37..4329829e 100644 --- a/commands/bug/completion.go +++ b/commands/bug/completion.go @@ -9,7 +9,7 @@ import ( "github.com/git-bug/git-bug/commands/completion" "github.com/git-bug/git-bug/commands/execenv" _select "github.com/git-bug/git-bug/commands/select" - "github.com/git-bug/git-bug/entities/bug" + "github.com/git-bug/git-bug/entities/common" ) // BugCompletion complete a bug id @@ -61,26 +61,26 @@ func BugAndLabelsCompletion(env *execenv.Env, addOrRemove bool) completion.Valid snap := b.Snapshot() - seenLabels := map[bug.Label]bool{} + seenLabels := map[common.Label]bool{} for _, label := range cleanArgs { - seenLabels[bug.Label(label)] = addOrRemove + seenLabels[common.Label(label)] = addOrRemove } - var labels []bug.Label + var labels []common.Label if addOrRemove { for _, label := range snap.Labels { seenLabels[label] = true } allLabels := env.Backend.Bugs().ValidLabels() - labels = make([]bug.Label, 0, len(allLabels)) + labels = make([]common.Label, 0, len(allLabels)) for _, label := range allLabels { if !seenLabels[label] { labels = append(labels, label) } } } else { - labels = make([]bug.Label, 0, len(snap.Labels)) + labels = make([]common.Label, 0, len(snap.Labels)) for _, label := range snap.Labels { if seenLabels[label] { labels = append(labels, label) diff --git a/commands/cmdjson/bug.go b/commands/cmdjson/bug.go index a7f894ed..62eae92b 100644 --- a/commands/cmdjson/bug.go +++ b/commands/cmdjson/bug.go @@ -3,20 +3,21 @@ package cmdjson import ( "github.com/git-bug/git-bug/cache" "github.com/git-bug/git-bug/entities/bug" + "github.com/git-bug/git-bug/entities/common" ) type BugSnapshot struct { - Id string `json:"id"` - HumanId string `json:"human_id"` - CreateTime Time `json:"create_time"` - EditTime Time `json:"edit_time"` - Status string `json:"status"` - Labels []bug.Label `json:"labels"` - Title string `json:"title"` - Author Identity `json:"author"` - Actors []Identity `json:"actors"` - Participants []Identity `json:"participants"` - Comments []BugComment `json:"comments"` + Id string `json:"id"` + HumanId string `json:"human_id"` + CreateTime Time `json:"create_time"` + EditTime Time `json:"edit_time"` + Status string `json:"status"` + Labels []common.Label `json:"labels"` + Title string `json:"title"` + Author Identity `json:"author"` + Actors []Identity `json:"actors"` + Participants []Identity `json:"participants"` + Comments []BugComment `json:"comments"` } func NewBugSnapshot(snap *bug.Snapshot) BugSnapshot { @@ -71,12 +72,12 @@ type BugExcerpt struct { CreateTime Time `json:"create_time"` EditTime Time `json:"edit_time"` - Status string `json:"status"` - Labels []bug.Label `json:"labels"` - Title string `json:"title"` - Actors []Identity `json:"actors"` - Participants []Identity `json:"participants"` - Author Identity `json:"author"` + Status string `json:"status"` + Labels []common.Label `json:"labels"` + Title string `json:"title"` + Actors []Identity `json:"actors"` + Participants []Identity `json:"participants"` + Author Identity `json:"author"` Comments int `json:"comments"` Metadata map[string]string `json:"metadata"` -- cgit