Skip to content

Commit

Permalink
Adopt CEL expressions for ignoring issues
Browse files Browse the repository at this point in the history
With intent to let teams ignore the parent link rule
  • Loading branch information
ralphbean committed Apr 12, 2024
1 parent 029a3e6 commit 081a74e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
22 changes: 8 additions & 14 deletions config/konflux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
10 changes: 8 additions & 2 deletions config/rhtapwatch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/rules/team/due_date.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
15 changes: 14 additions & 1 deletion src/rules/team/parent.py
Original file line number Diff line number Diff line change
@@ -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.")
12 changes: 12 additions & 0 deletions src/utils/cel.py
Original file line number Diff line number Diff line change
@@ -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]
),
)
1 change: 1 addition & 0 deletions tools/release/dependencies/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cel-python
click
jira
pyyaml
Expand Down

0 comments on commit 081a74e

Please sign in to comment.