aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-21 14:02:05 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-21 14:02:05 +0200
commit6e4475941309b1b8aed7415b948ba6d26d80dfad (patch)
tree727a761970b6a7cbc3558918e253616843a1422f /cache
parentcfce3a9914c4a7762399119fabc63c77f567d7cf (diff)
downloadgit-bug-6e4475941309b1b8aed7415b948ba6d26d80dfad.tar.gz
commands: add a "ls-labels" command that output valid labels
Diffstat (limited to 'cache')
-rw-r--r--cache/repo_cache.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 7ae8bb1d..26f2855f 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -281,6 +281,36 @@ func (c *RepoCache) ClearAllBugs() {
c.bugs = make(map[string]*BugCache)
}
+// ValidLabels list valid labels
+//
+// Note: in the future, a proper label policy could be implemented where valid
+// labels are defined in a configuration file. Until that, the default behavior
+// is to return the list of labels already used.
+func (c *RepoCache) ValidLabels() []bug.Label {
+ set := map[bug.Label]interface{}{}
+
+ for _, excerpt := range c.excerpts {
+ for _, l := range excerpt.Labels {
+ set[l] = nil
+ }
+ }
+
+ result := make([]bug.Label, len(set))
+
+ i := 0
+ for l := range set {
+ result[i] = l
+ i++
+ }
+
+ // Sort
+ sort.Slice(result, func(i, j int) bool {
+ return string(result[i]) < string(result[j])
+ })
+
+ return result
+}
+
// NewBug create a new bug
// The new bug is written in the repository (commit)
func (c *RepoCache) NewBug(title string, message string) (*BugCache, error) {