diff --git a/core/jira_handler.py b/core/jira_handler.py index ac4b60e..d3f827c 100644 --- a/core/jira_handler.py +++ b/core/jira_handler.py @@ -20,11 +20,11 @@ def ticket_handler(self): entity_scorecard = entity.get("scorecards", {}).get( self.scorecard.get("identifier"), {} ) - rules_by_level = {"Gold": [], "Silver": [], "Bronze": []} + rules_by_level = {} # Grouping rules by levels for rule in entity_scorecard.get("rules", []): - rules_by_level[rule.get("level")].append(rule) + rules_by_level.setdefault(rule.get("level"), []).append(rule) for level in rules_by_level: scorecard_level_completed = all( diff --git a/generators/slack.py b/generators/slack.py index 28aafb7..36bbc8d 100644 --- a/generators/slack.py +++ b/generators/slack.py @@ -13,18 +13,21 @@ class SlackMessageGenerator(generators.base.BaseMessageGenerator): def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities: list): blueprint_plural = utils.convert_to_plural(blueprint).title() - entities_by_level = { - "Gold": [], - "Silver": [], - "Bronze": [], - "Basic": [], - } + most_advanced_level: str = self._get_most_advanced_scorecard_level( + scorecard + ) + entities_by_level = {} overall_entities_per_team = {} - gold_entities_per_team = {} + most_advanced_entities_per_team = {} number_of_passed_entities_per_rule = {} for entity in entities: - entity_scorecard_result = entity.get("scorecards", {}).get(scorecard.get("identifier"), {}) - entities_by_level[entity_scorecard_result.get("level")].append( + entity_scorecard_result = entity.get( + "scorecards", {} + ).get(scorecard.get("identifier"), {}) + entities_by_level.setdefault( + entity_scorecard_result.get("level"), + [] + ).append( { "identifier": entity.get("identifier"), "name": entity.get("title"), @@ -32,8 +35,8 @@ def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities: ) for team in entity.get("team", []): overall_entities_per_team[team] = overall_entities_per_team.get(team, 0) + 1 - if entity_scorecard_result.get("level") == "Gold": - gold_entities_per_team[team] = gold_entities_per_team.get(team, 0) + 1 + if entity_scorecard_result.get("level") == most_advanced_level: + most_advanced_entities_per_team[team] = most_advanced_entities_per_team.get(team, 0) + 1 for rule in entity_scorecard_result.get("rules", []): number_of_passed_entities_per_rule[rule.get("identifier")] = \ @@ -181,24 +184,29 @@ def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities: ] return blocks - def scorecard_reminder(self, - blueprint: str, - scorecard: Dict[str, Any], - entities: list) -> List[Dict[str, Any]]: + def scorecard_reminder( + self, + blueprint: str, + scorecard: Dict[str, Any], + entities: list + ) -> List[Dict[str, Any]]: blueprint_plural = utils.convert_to_plural(blueprint).title() - entities_didnt_pass_all_rules = { - "Silver": [], - "Bronze": [], - "Basic": [], - } + most_advanced_level: str = self._get_most_advanced_scorecard_level( + scorecard + ) + + entities_didnt_pass_all_rules = {} 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": + if entity_scorecard_result.get("level") != most_advanced_level: passed_rules = [rule for rule in entity_scorecard_result.get("rules", []) if rule.get("status") == "SUCCESS"] or [] if len(passed_rules) < number_of_rules: - entities_didnt_pass_all_rules[entity_scorecard_result.get("level")].append( + entities_didnt_pass_all_rules.setdefault( + entity_scorecard_result.get("level"), + [] + ).append( { "identifier": entity.get("identifier"), "name": entity.get("title"), @@ -242,6 +250,17 @@ def scorecard_reminder(self, ) ] return blocks + + @staticmethod + def _get_most_advanced_scorecard_level(scorecard: dict[str, Any]) -> str | None: + """ + Get the most advanced level of a scorecard + """ + + scorecard_levels = scorecard.get("levels") + + most_advanced_level: str = scorecard_levels[-1].get("title") + return most_advanced_level @staticmethod def _resolve_top_highest_lowest_scored_rules(entities: list,