From 081a74e50ce55c083761599d6ea64b8babe975e9 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Fri, 12 Apr 2024 12:27:38 -0400 Subject: [PATCH] Adopt CEL expressions for ignoring issues With intent to let teams ignore the parent link rule --- config/konflux.yaml | 22 ++++++++------------- config/rhtapwatch.yaml | 10 ++++++++-- src/rules/team/due_date.py | 18 ++++++++++------- src/rules/team/parent.py | 15 +++++++++++++- src/utils/cel.py | 12 +++++++++++ tools/release/dependencies/requirements.txt | 1 + 6 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 src/utils/cel.py diff --git a/config/konflux.yaml b/config/konflux.yaml index e0808c7..1104c90 100644 --- a/config/konflux.yaml +++ b/config/konflux.yaml @@ -31,17 +31,11 @@ team_automation: rules: - rule: check_due_date kwargs: - ignore: - - SVPI-730 - - STONEINTG-767 - - STONEBLD-2116 - - RHTAPWATCH-743 - - RHTAPSRE-366 - - RHTAPREL-809 - - PLNSRVCE-1605 - - HAC-5626 - - GITOPSRVCE-800 - - EC-367 - - DEVHAS-606 - - ASC-454 - - PSSECAUT-362 + # This is a CEL expression + ignore: > + .key in [ + "SVPI-730", "STONEINTG-767", "STONEBLD-2116", "RHTAPWATCH-743", + "RHTAPSRE-366", "RHTAPREL-809", "PLNSRVCE-1605", "HAC-5626", + "GITOPSRVCE-800", "EC-367", "DEVHAS-606", "ASC-454", + "PSSECAUT-362" + ] diff --git a/config/rhtapwatch.yaml b/config/rhtapwatch.yaml index 0b8eca9..b71335e 100644 --- a/config/rhtapwatch.yaml +++ b/config/rhtapwatch.yaml @@ -7,7 +7,10 @@ team_automation: Epic: # collector: get_issues rules: - - check_parent_link + - rule: check_parent_link + kwargs: + # This is a CEL expression + ignore: '"orphan" in .labels' - check_priority - check_due_date - check_target_dates @@ -16,7 +19,10 @@ team_automation: Story: # collector: get_issues rules: - - check_parent_link + - rule: check_parent_link + kwargs: + # This is a CEL expression + ignore: '"orphan" in .labels' - check_priority - check_quarter_label - check_due_date diff --git a/src/rules/team/due_date.py b/src/rules/team/due_date.py index 3b3fe66..65d5ad0 100644 --- a/src/rules/team/due_date.py +++ b/src/rules/team/due_date.py @@ -1,21 +1,25 @@ from time import strftime +import celpy import jira +from utils.cel import issue_as_cel from utils.jira import update today = strftime("%Y-%m-%d") def check_due_date( - issue: jira.resources.Issue, context: dict, dry_run: bool, ignore: list = None + issue: jira.resources.Issue, context: dict, dry_run: bool, ignore: str = "" ) -> None: - ignore = ignore or [] - if issue.key in ignore: - context["updates"].append( - f"! Ignoring {issue.key} for due date rule, per config." - ) - return + if ignore: + env = celpy.Environment() + program = env.program(env.compile(ignore)) + if program.evaluate(issue_as_cel(issue)): + context["updates"].append( + f"! Ignoring {issue.key} for due date rule, per cel expression {ignore}." + ) + return related_issues = list(issue.raw["Context"]["Related Issues"]["Blocks"]) parent_issue = issue.raw["Context"]["Related Issues"]["Parent"] diff --git a/src/rules/team/parent.py b/src/rules/team/parent.py index 481e7ce..97461d3 100644 --- a/src/rules/team/parent.py +++ b/src/rules/team/parent.py @@ -1,7 +1,20 @@ +import celpy import jira +from utils.cel import issue_as_cel -def check_parent_link(issue: jira.resources.Issue, context: dict, _: bool) -> None: + +def check_parent_link( + issue: jira.resources.Issue, context: dict, _: bool, ignore: str = "" +) -> None: + if ignore: + env = celpy.Environment() + program = env.program(env.compile(ignore)) + if program.evaluate(issue_as_cel(issue)): + context["updates"].append( + f"! Ignoring {issue.key} for parent link rule, per cel expression {ignore}." + ) + return if issue.raw["Context"]["Related Issues"]["Parent"] is None: context["non-compliant"] = True context["comments"].append(" * Issue is missing the link to its parent.") diff --git a/src/utils/cel.py b/src/utils/cel.py new file mode 100644 index 0000000..bd1d243 --- /dev/null +++ b/src/utils/cel.py @@ -0,0 +1,12 @@ +import celpy +import jira + + +def issue_as_cel(issue: jira.resources.Issue): + return dict( + key=issue.key, + labels=celpy.json_to_cel([label for label in issue.fields.labels]), + components=celpy.json_to_cel( + [component.name for component in issue.fields.components] + ), + ) diff --git a/tools/release/dependencies/requirements.txt b/tools/release/dependencies/requirements.txt index 316b42f..d7c3ce6 100644 --- a/tools/release/dependencies/requirements.txt +++ b/tools/release/dependencies/requirements.txt @@ -1,3 +1,4 @@ +cel-python click jira pyyaml