Skip to content

Commit

Permalink
Add hierarchy to handle multiple matching rules for a failure (#193)
Browse files Browse the repository at this point in the history
* Sort matching_rules by the identical rules to failure.step

* Add test_configuration_gets_failure_rules_with_two_matching_steps

* Update unittest with adding rule with different type

* Revert "Update unittest with adding rule with different type"

This reverts commit dc56944.
  • Loading branch information
oharan2 authored May 21, 2024
1 parent e34cf55 commit 2cf80ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ def failure_matches_rule(
if default_rule not in matching_rules:
matching_rules.append(default_rule)

# Sort matching_rules by the identical rules to failure.step
if matching_rules:
matching_rules = sorted(matching_rules, key=lambda x: x.step.__eq__(failure.step), reverse=True)
return matching_rules

def add_passing_job_comment(self, job: Job, jira: Jira, issue_id: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,32 @@ def test_failure_matches_rule_with_matches(self):
assert (matching_rules[0].step == match_rule.step) and (
matching_rules[0].failure_type == match_rule.failure_type
)

def test_configuration_gets_failure_rules_with_two_matching_steps(self):
failure = Failure(failed_step="exact-failed-step", failure_type="test_failure")

match_rule = FailureRule(
rule_dict={
"step": "exact-failed-step",
"failure_type": "test_failure",
"classification": "NONE",
"jira_project": "NONE",
},
)
pattern_rule = FailureRule(
rule_dict={
"step": "exact-*",
"failure_type": "test_failure",
"classification": "NONE",
"jira_project": "NONE",
},
)
rules = [pattern_rule, match_rule]

matching_rules = self.report.failure_matches_rule(
failure=failure,
rules=rules,
default_jira_project=self.config.default_jira_project,
)
# Check if match_rule is sorted higher than pattern_rule
assert matching_rules[0].step.__eq__(failure.step)

0 comments on commit 2cf80ec

Please sign in to comment.