Skip to content

Commit

Permalink
Merge pull request #43 from grafana/fix-name-of-required-labels
Browse files Browse the repository at this point in the history
rename required_labels to requireLabel
  • Loading branch information
replay authored Aug 2, 2024
2 parents 7234171 + 13fad36 commit aa440d3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
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
14 changes: 8 additions & 6 deletions pkg/labeler/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
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"

0 comments on commit aa440d3

Please sign in to comment.