Skip to content

Commit

Permalink
Add support for custom scorecards (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
lordsarcastic authored Aug 20, 2024
1 parent 52b20ad commit fe0d78b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
4 changes: 2 additions & 2 deletions core/jira_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
63 changes: 41 additions & 22 deletions generators/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@ 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"),
}
)
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")] = \
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fe0d78b

Please sign in to comment.