diff --git a/ic-assignment/action.yml b/ic-assignment/action.yml index 0adcdd5..497a364 100644 --- a/ic-assignment/action.yml +++ b/ic-assignment/action.yml @@ -21,4 +21,4 @@ outputs: description: "The output property of the assigned person. If output property is empty, name is used instead" runs: using: "docker" - image: "docker://ghcr.io/grafana/issue-team-scheduler-ic-assignment:v0.13" + image: "docker://ghcr.io/grafana/issue-team-scheduler-ic-assignment:v0.14" diff --git a/pkg/labeler/config.go b/pkg/labeler/config.go index e85671f..b89f949 100644 --- a/pkg/labeler/config.go +++ b/pkg/labeler/config.go @@ -27,8 +27,8 @@ type Config struct { // The label with the highest score is applied to the issue. Labels map[string]Label `yaml:"labels,omitempty"` - // RequiredLabels is a list of labels that must be present on the issue for any other labels to be applied. - RequiredLabels []string `yaml:"required_labels,omitempty"` + // RequireLabel is a list of labels, for the regex-labeler to run at least one of the specified labels must be present on the issue. + RequireLabel []string `yaml:"requireLabel,omitempty"` } func (c *Config) Validate() error { diff --git a/pkg/labeler/labeler.go b/pkg/labeler/labeler.go index f34af2f..fd62608 100644 --- a/pkg/labeler/labeler.go +++ b/pkg/labeler/labeler.go @@ -44,10 +44,11 @@ func NewLabeler(cfg Config, gh *github.Client, logger log.Logger) *Labeler { func (l *Labeler) Run(issue *github.Issue) error { if !l.hasRequiredLabels(issue) { + level.Info(l.logger).Log("msg", "issue has none of the required labels", "requireLabel", strings.Join(l.cfg.RequireLabel, ", ")) return nil } - level.Info(l.logger).Log("msg", "issue has the required labels", "required_labels", strings.Join(l.cfg.RequiredLabels, ", ")) + level.Info(l.logger).Log("msg", "issue has at least one of the required labels", "requireLabel", strings.Join(l.cfg.RequireLabel, ", ")) if l.hasAssignableLabel(issue) { return nil @@ -155,12 +156,13 @@ func (l *Labeler) hasAssignableLabel(issue *github.Issue) bool { func (l *Labeler) hasRequiredLabels(issue *github.Issue) bool { issueLabels := getIssueLabels(issue) - for _, requiredLabel := range l.cfg.RequiredLabels { - if !slices.Contains[[]string, string](issueLabels, requiredLabel) { - level.Info(l.logger).Log("msg", "issue is missing required label", "label", requiredLabel) - return false + match := false + for _, requiredLabel := range l.cfg.RequireLabel { + if slices.Contains[[]string, string](issueLabels, requiredLabel) { + match = true } + } - return true + return match } diff --git a/pkg/labeler/labeler_test.go b/pkg/labeler/labeler_test.go index 0727c93..3482e4c 100644 --- a/pkg/labeler/labeler_test.go +++ b/pkg/labeler/labeler_test.go @@ -42,6 +42,7 @@ func TestAssigningLabel(t *testing.T) { { name: "assign the mimir-query label", cfg: Config{ + RequireLabel: []string{"label1", "label3"}, Labels: map[string]Label{ "mimir-ingest": { Matchers: []Matcher{ @@ -77,6 +78,32 @@ func TestAssigningLabel(t *testing.T) { issueNumber: testIssueNumber, labels: []string{"label1", "label2", "mimir-query"}, }}, + }, { + name: "don't assign label due to lack of required labels", + cfg: Config{ + RequireLabel: []string{"label1", "label2"}, + Labels: map[string]Label{ + "mimir-query": { + Matchers: []Matcher{ + { + regex: regexp.MustCompile(`.*`), + Weight: 1, + }, + }, + }, + }, + }, + issue: &github.Issue{ + Number: &testIssueNumber, + Title: github.String("some title"), + Body: github.String("some body abc something something query more text."), + RepositoryURL: &testRepositoreURL, + Labels: []github.Label{ + {Name: github.String("label3")}, + {Name: github.String("label4")}, + }, + }, + expectedLabelAssignerCalls: nil, }, } diff --git a/regex-labeler/action.yml b/regex-labeler/action.yml index 0ab1056..663faaa 100644 --- a/regex-labeler/action.yml +++ b/regex-labeler/action.yml @@ -9,4 +9,4 @@ inputs: description: "GitHub token to use for API calls" runs: using: "docker" - image: "docker://ghcr.io/grafana/issue-team-scheduler-regex-labeler:v0.13" + image: "docker://ghcr.io/grafana/issue-team-scheduler-regex-labeler:v0.14"