-
Notifications
You must be signed in to change notification settings - Fork 0
/
labels.go
72 lines (63 loc) · 1.9 KB
/
labels.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package labels
import (
"fmt"
"sort"
"strings"
"github.com/CircleCI-Public/circleci-config/labeling/codebase"
)
const (
ArtifactGoExecutable = "artifact:go-executable"
ArtifactRustCrate = "artifact:rust-crate"
DepsGo = "deps:go"
DepsJava = "deps:java"
DepsNode = "deps:node"
DepsPython = "deps:python"
DepsRuby = "deps:ruby"
DepsRust = "deps:rust"
DepsPhp = "deps:php"
PackageManagerPipenv = "package_manager:pipenv"
PackageManagerPoetry = "package_manager:poetry"
PackageManagerYarn = "package_manager:yarn"
PackageManagerGemspec = "package_manager:gemspec"
CICDGithubActions = "cicd:github-actions"
CICDGitlabWorkflow = "cicd:gitlab-workflows"
CICDJenkins = "cicd:jenkins"
EmptyRepo = "cicd:empty"
TestJest = "test:jest"
ToolGradle = "tool:gradle"
FileManagePy = "file:manage.py"
FileSetupPy = "file:setup.py"
TestTox = "test:tox"
)
type LabelData struct {
BasePath string
Dependencies map[string]string
Tasks map[string]string
HasLockFile bool
Version string
}
// Label is the result of applying a Rule
type Label struct {
Key string // string identifying the label, like "deps:go"
Valid bool // If the rule applies, Valid = true
LabelData // LabelData rule-specific data for each label
}
func (label Label) String() string {
if label.Valid {
return fmt.Sprintf("%s:%s", label.Key, label.BasePath)
} else {
return fmt.Sprintf("!%s", label.Key)
}
}
type LabelSet map[string]Label
func (ls LabelSet) String() string {
labelsAsStrings := make([]string, len(ls))
i := 0
for _, v := range ls {
labelsAsStrings[i] = v.String()
i++
}
sort.Strings(labelsAsStrings)
return strings.Join(labelsAsStrings, ",")
}
type Rule func(codebase.Codebase, LabelSet) (Label, error)