fix(filters): handle empty tag_match_logic by defaulting to ANY (#910)

* speculative fix for tags_match_logic if set to ANY

* add default tag match logic handling

* fixed test cases and rejection messages

* trim tags in match funcs

* add test for empty TagsMatchLogic
This commit is contained in:
soup 2023-05-06 16:11:34 +02:00 committed by GitHub
parent 537bbe3394
commit 8a1910843c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 10 deletions

View file

@ -388,18 +388,18 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) {
}
if f.Tags != "" {
if f.TagsMatchLogic == "ANY" && !containsAny(r.Tags, f.Tags) {
r.addRejectionF("tags not matching. got: %v want: %v", r.Tags, f.Tags)
} else if f.TagsMatchLogic == "ALL" && !containsAll(r.Tags, f.Tags) {
if f.TagsMatchLogic == "ALL" && !containsAll(r.Tags, f.Tags) {
r.addRejectionF("tags not matching. got: %v want(all): %v", r.Tags, f.Tags)
} else if !containsAny(r.Tags, f.Tags) { // TagsMatchLogic is set to "" by default, this makes sure that "" and "ANY" are treated the same way.
r.addRejectionF("tags not matching. got: %v want: %v", r.Tags, f.Tags)
}
}
if f.ExceptTags != "" {
if f.ExceptTagsMatchLogic == "ANY" && containsAny(r.Tags, f.ExceptTags) {
r.addRejectionF("tags unwanted. got: %v want: %v", r.Tags, f.ExceptTags)
} else if f.ExceptTagsMatchLogic == "ALL" && containsAll(r.Tags, f.ExceptTags) {
r.addRejectionF("tags unwanted. got: %v want(all): %v", r.Tags, f.ExceptTags)
if f.ExceptTagsMatchLogic == "ALL" && containsAll(r.Tags, f.ExceptTags) {
r.addRejectionF("tags unwanted. got: %v don't want: %v", r.Tags, f.ExceptTags)
} else if containsAny(r.Tags, f.ExceptTags) { // ExceptTagsMatchLogic is set to "" by default, this makes sure that "" and "ANY" are treated the same way.
r.addRejectionF("tags unwanted. got: %v don't want: %v", r.Tags, f.ExceptTags)
}
}
@ -683,6 +683,7 @@ func containsMatch(tags []string, filters []string) bool {
continue
}
tag = strings.ToLower(tag)
tag = strings.Trim(tag, " ")
for _, filter := range filters {
if filter == "" {
@ -720,6 +721,7 @@ func containsAllMatch(tags []string, filters []string) bool {
continue
}
tag = strings.ToLower(tag)
tag = strings.Trim(tag, " ")
if tag == filter {
found = true