diff --git a/generators/slack.py b/generators/slack.py index 29aaaeb..f830945 100644 --- a/generators/slack.py +++ b/generators/slack.py @@ -183,30 +183,31 @@ def scorecard_reminder(self, scorecard: Dict[str, Any], entities: list) -> List[Dict[str, Any]]: blueprint_plural = utils.convert_to_plural(blueprint).title() - entities_didnt_pass_gold_level = { + entities_didnt_pass_all_rules = { "Silver": [], "Bronze": [], "Basic": [], } - number_of_entities_didnt_pass_gold_level = 0 + number_of_entities_didnt_pass_all_rules = 0 for entity in entities: entity_scorecard_result = entity.get("scorecards", {}).get(scorecard.get("identifier"), {}) number_of_rules = len(entity_scorecard_result.get("rules", [])) if entity_scorecard_result.get("level") != "Gold": passed_rules = [rule for rule in entity_scorecard_result.get("rules", []) if rule.get("status") == "SUCCESS"] or [] - entities_didnt_pass_gold_level[entity_scorecard_result.get("level")].append( - { - "identifier": entity.get("identifier"), - "name": entity.get("title"), - "passed_rules": passed_rules, - "number_of_rules": number_of_rules - } - ) - number_of_entities_didnt_pass_gold_level += 1 + if len(passed_rules) < number_of_rules: + entities_didnt_pass_all_rules[entity_scorecard_result.get("level")].append( + { + "identifier": entity.get("identifier"), + "name": entity.get("title"), + "passed_rules": passed_rules, + "number_of_rules": number_of_rules + } + ) + number_of_entities_didnt_pass_all_rules += 1 - entities_didnt_pass_gold_level_sorted = { + entities_didnt_pass_all_rules = { level: sorted(entities, key=lambda item: len(item.get("passed_rules", [])), reverse=True) - for level, entities in entities_didnt_pass_gold_level.items() + for level, entities in entities_didnt_pass_all_rules.items() } blocks = [ @@ -229,7 +230,7 @@ def scorecard_reminder(self, "type": "section", "text": { "type": "mrkdwn", - "text": f"*⚠️ {number_of_entities_didnt_pass_gold_level} {blueprint_plural} with unmet rules*" + "text": f"*⚠️ {number_of_entities_didnt_pass_all_rules} {blueprint_plural} with unmet rules*" } }, { @@ -237,7 +238,7 @@ def scorecard_reminder(self, "text": { "type": "mrkdwn", "text": self._generate_entities_list_with_level_and_link(blueprint, - entities_didnt_pass_gold_level_sorted) + entities_didnt_pass_all_rules) } } ]