From 6cd4abb80d8e55a1bd2db717b2f16f0264594099 Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Fri, 2 Aug 2024 09:37:41 +0200 Subject: [PATCH 1/7] rename required_labels to requireLabel Signed-off-by: Mauro Stettler --- pkg/labeler/config.go | 4 ++-- pkg/labeler/labeler.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/labeler/config.go b/pkg/labeler/config.go index e85671f..f868966 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 that must be present on the issue for any other labels to be applied. + RequireLabel []string `yaml:"requireLabel,omitempty"` } func (c *Config) Validate() error { diff --git a/pkg/labeler/labeler.go b/pkg/labeler/labeler.go index f34af2f..9bb09c5 100644 --- a/pkg/labeler/labeler.go +++ b/pkg/labeler/labeler.go @@ -47,7 +47,7 @@ func (l *Labeler) Run(issue *github.Issue) error { 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 the required labels", "required_labels", strings.Join(l.cfg.RequireLabel, ", ")) if l.hasAssignableLabel(issue) { return nil @@ -155,7 +155,7 @@ 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 { + for _, requiredLabel := range l.cfg.RequireLabel { if !slices.Contains[[]string, string](issueLabels, requiredLabel) { level.Info(l.logger).Log("msg", "issue is missing required label", "label", requiredLabel) return false From 260fc016b0123fa342fe34bc15c3b79696331569 Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Fri, 2 Aug 2024 09:40:30 +0200 Subject: [PATCH 2/7] update version numbers Signed-off-by: Mauro Stettler --- ic-assignment/action.yml | 2 +- regex-labeler/action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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" From c5767af2194f1ffc3a424e6ea0e5ec810ee89e11 Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Fri, 2 Aug 2024 09:46:19 +0200 Subject: [PATCH 3/7] make behavior consistent Signed-off-by: Mauro Stettler --- pkg/labeler/config.go | 2 +- pkg/labeler/labeler.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/labeler/config.go b/pkg/labeler/config.go index f868966..b89f949 100644 --- a/pkg/labeler/config.go +++ b/pkg/labeler/config.go @@ -27,7 +27,7 @@ type Config struct { // The label with the highest score is applied to the issue. Labels map[string]Label `yaml:"labels,omitempty"` - // RequireLabel is a list of labels that must be present on the issue for any other labels to be applied. + // 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"` } diff --git a/pkg/labeler/labeler.go b/pkg/labeler/labeler.go index 9bb09c5..73344c5 100644 --- a/pkg/labeler/labeler.go +++ b/pkg/labeler/labeler.go @@ -155,12 +155,17 @@ func (l *Labeler) hasAssignableLabel(issue *github.Issue) bool { func (l *Labeler) hasRequiredLabels(issue *github.Issue) bool { issueLabels := getIssueLabels(issue) + match := false for _, requiredLabel := range l.cfg.RequireLabel { - if !slices.Contains[[]string, string](issueLabels, requiredLabel) { - level.Info(l.logger).Log("msg", "issue is missing required label", "label", requiredLabel) - return false + if slices.Contains[[]string, string](issueLabels, requiredLabel) { + match = true } + + } + + if !match { + level.Info(l.logger).Log("msg", "issue has none of the required labels", "requireLabel", strings.Join(l.cfg.RequireLabel, ",")) } - return true + return match } From a7eeeb049e85244a988ee2cb109f349c3617769b Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Fri, 2 Aug 2024 09:49:01 +0200 Subject: [PATCH 4/7] fix test case Signed-off-by: Mauro Stettler --- pkg/labeler/labeler_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/labeler/labeler_test.go b/pkg/labeler/labeler_test.go index 0727c93..bb5ecac 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"}, Labels: map[string]Label{ "mimir-ingest": { Matchers: []Matcher{ From 44afd5789523ec4fa2b74e287ccb7b3dcd8448f2 Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Fri, 2 Aug 2024 09:50:16 +0200 Subject: [PATCH 5/7] add test skipping assignment Signed-off-by: Mauro Stettler --- pkg/labeler/labeler_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/labeler/labeler_test.go b/pkg/labeler/labeler_test.go index bb5ecac..9f374ed 100644 --- a/pkg/labeler/labeler_test.go +++ b/pkg/labeler/labeler_test.go @@ -78,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, }, } From 584cc525af4e9dcecdf1d2fe0595d862e2350b72 Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Fri, 2 Aug 2024 09:51:16 +0200 Subject: [PATCH 6/7] only one of the required labels must be present Signed-off-by: Mauro Stettler --- pkg/labeler/labeler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/labeler/labeler_test.go b/pkg/labeler/labeler_test.go index 9f374ed..3482e4c 100644 --- a/pkg/labeler/labeler_test.go +++ b/pkg/labeler/labeler_test.go @@ -42,7 +42,7 @@ func TestAssigningLabel(t *testing.T) { { name: "assign the mimir-query label", cfg: Config{ - RequireLabel: []string{"label1"}, + RequireLabel: []string{"label1", "label3"}, Labels: map[string]Label{ "mimir-ingest": { Matchers: []Matcher{ From 13fad36e66816a857d9602df19fe294ed99dd725 Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Fri, 2 Aug 2024 10:03:49 +0200 Subject: [PATCH 7/7] more consistent log statement Signed-off-by: Mauro Stettler --- pkg/labeler/labeler.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/labeler/labeler.go b/pkg/labeler/labeler.go index 73344c5..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.RequireLabel, ", ")) + 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 @@ -163,9 +164,5 @@ func (l *Labeler) hasRequiredLabels(issue *github.Issue) bool { } - if !match { - level.Info(l.logger).Log("msg", "issue has none of the required labels", "requireLabel", strings.Join(l.cfg.RequireLabel, ",")) - } - return match }