Skip to content

Commit

Permalink
✨ Deduplicating Labels (#296)
Browse files Browse the repository at this point in the history
This pull request addresses issue #295. I resolved the problem, of
duplicate labels appearing both in violations and rules after adding
labels from the ruleset, by introducing a function that flags all
duplicate values within the labels array.
@pranavgaikwad please check.

---------

Signed-off-by: AdiAkhileshSingh15 <[email protected]>
  • Loading branch information
AdiAkhileshSingh15 authored Aug 23, 2023
1 parent 20ec4dc commit 8af6167
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ func (r *ruleEngine) createViolation(conditionResponse ConditionResponse, rule R
}
}

rule.Labels = deduplicateLabels(rule.Labels)

return konveyor.Violation{
Description: rule.Description,
Labels: rule.Labels,
Expand Down Expand Up @@ -558,3 +560,18 @@ func matchesAllSelectors(m RuleMeta, selectors ...RuleSelector) bool {
}
return true
}

func deduplicateLabels(labels []string) []string {
present := map[string]bool{}
uniquelabels := []string{}

for _, label := range labels {
if !present[label] {
present[label] = true
uniquelabels = append(uniquelabels, label)
}
}

return uniquelabels

}

0 comments on commit 8af6167

Please sign in to comment.