-
Notifications
You must be signed in to change notification settings - Fork 0
/
labeling.go
50 lines (44 loc) · 1.23 KB
/
labeling.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package labeling
import (
"github.com/CircleCI-Public/circleci-config/labeling/codebase"
"github.com/CircleCI-Public/circleci-config/labeling/internal"
"github.com/CircleCI-Public/circleci-config/labeling/labels"
)
// ApplyRules applies the rules to a codebase.Codebase and returns a map of label key to
// valid codebase.Label
// Order of rules is relevant, higher "salience" rules should come first, i.e. later rules can
// depend on the LabelData of previous rules.
func ApplyRules(c codebase.Codebase, rules []labels.Rule) labels.LabelSet {
ls := make(labels.LabelSet)
for _, r := range rules {
label, err := r(c, ls)
if err != nil {
continue
}
if label.Valid {
ls[label.Key] = label
}
}
return ls
}
func ApplyAllRules(c codebase.Codebase) labels.LabelSet {
allStacks := [][]labels.Rule{
internal.GoRules,
internal.JavaRules,
internal.NodeRules,
internal.PythonRules,
internal.RubyRules,
internal.RustRules,
internal.PhpRules,
internal.GithubActionRules,
internal.GitlabWorkflowRules,
internal.JenkinsRules,
internal.EmptyRepoRules,
// Add other stacks here
}
var allRules []labels.Rule
for _, stack := range allStacks {
allRules = append(allRules, stack...)
}
return ApplyRules(c, allRules)
}