Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hierarchy to handle multiple matching rules for a failure #193

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
calebevans marked this conversation as resolved.
Show resolved Hide resolved
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)
Loading