Skip to content

Commit 261dc8d

Browse files
committed
improve NOT matchCondition
Signed-off-by: Jeffrey Sica <[email protected]>
1 parent 5cea190 commit 261dc8d

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

utilities/labeler/main.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func main() {
163163
log.Printf("error matching file path: %v", err)
164164
continue
165165
}
166-
if matched {
166+
if matched || (rule.Spec.MatchCondition == "NOT" && !matched) {
167167
for _, action := range rule.Actions {
168168
label := renderLabel(action.Spec.Label, nil)
169169
switch action.Kind {
@@ -247,33 +247,31 @@ func main() {
247247
}
248248
} else if rule.Kind == "label" {
249249
// Handle default namespaced label logic dynamically
250-
if rule.Spec.MatchCondition == "NOT" {
251-
namespacePattern := rule.Spec.Match
252-
existingLabels, _, err := client.Issues.ListLabelsByIssue(ctx, owner, repo, toInt(issueNum), nil)
253-
if err != nil {
254-
log.Printf("failed to fetch labels for issue: %v", err)
255-
continue
256-
}
250+
namespacePattern := rule.Spec.Match
251+
existingLabels, _, err := client.Issues.ListLabelsByIssue(ctx, owner, repo, toInt(issueNum), nil)
252+
if err != nil {
253+
log.Printf("failed to fetch labels for issue: %v", err)
254+
continue
255+
}
257256

258-
foundNamespace := false
259-
for _, lbl := range existingLabels {
260-
matched, _ := filepath.Match(namespacePattern, lbl.GetName())
261-
if matched {
262-
foundNamespace = true
263-
break
264-
}
257+
foundNamespace := false
258+
for _, lbl := range existingLabels {
259+
matched, _ := filepath.Match(namespacePattern, lbl.GetName())
260+
if matched || (rule.Spec.MatchCondition == "NOT" && !matched) {
261+
foundNamespace = true
262+
break
265263
}
264+
}
266265

267-
if !foundNamespace {
268-
for _, action := range rule.Actions {
269-
label := renderLabel(action.Spec.Label, nil)
270-
switch action.Kind {
271-
case "apply-label":
272-
applyLabel(ctx, client, owner, repo, toInt(issueNum), label, cfg)
273-
case "remove-label":
274-
if label != "" {
275-
removeLabel(ctx, client, owner, repo, toInt(issueNum), label)
276-
}
266+
if !foundNamespace {
267+
for _, action := range rule.Actions {
268+
label := renderLabel(action.Spec.Label, nil)
269+
switch action.Kind {
270+
case "apply-label":
271+
applyLabel(ctx, client, owner, repo, toInt(issueNum), label, cfg)
272+
case "remove-label":
273+
if label != "" {
274+
removeLabel(ctx, client, owner, repo, toInt(issueNum), label)
277275
}
278276
}
279277
}

0 commit comments

Comments
 (0)