Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename required_labels to requireLabel #43

Merged
merged 7 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ic-assignment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions pkg/labeler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 11 additions & 6 deletions pkg/labeler/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,12 +155,17 @@ 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
}

}

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
}
27 changes: 27 additions & 0 deletions pkg/labeler/labeler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
},
}

Expand Down
2 changes: 1 addition & 1 deletion regex-labeler/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading