Skip to content

Commit

Permalink
Fix slack reminders report not show all met rules with no gold rule (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tankilevitch authored Jan 2, 2024
1 parent d1d81a7 commit 9ab6077
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions generators/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -229,15 +230,15 @@ 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*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": self._generate_entities_list_with_level_and_link(blueprint,
entities_didnt_pass_gold_level_sorted)
entities_didnt_pass_all_rules)
}
}
]
Expand Down

0 comments on commit 9ab6077

Please sign in to comment.