Skip to content
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
63 changes: 40 additions & 23 deletions backend/kernelCI_app/management/commands/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,20 @@ def evaluate_test_results(
return new_issues, fixed_issues, unstable_tests


def process_submission_options(
*,
default_recipients: list[str],
specific_recipients: list[str],
options: list[PossibleReportOptions],
) -> list[str]:
recipients = default_recipients + specific_recipients

if "ignore_default_recipients" in options:
recipients = specific_recipients

return recipients


def run_checkout_summary(
*,
service,
Expand Down Expand Up @@ -470,28 +484,33 @@ def run_checkout_summary(
for tree_report in tree_report_list:
path = tree_report["path"] if "path" in tree_report else "%"

new_issues, fixed_issues, unstable_tests = evaluate_test_results(
origin=origin,
giturl=giturl,
branch=branch,
commit_hash=commit_hash,
path=path,
interval="7 days",
group_size=5,
)
# In case an error happens in the query, we don't want to send an empty report
try:
new_issues, fixed_issues, unstable_tests = evaluate_test_results(
origin=origin,
giturl=giturl,
branch=branch,
commit_hash=commit_hash,
path=path,
interval="7 days",
group_size=5,
)
except Exception as e:
log_message("Error while evaluating test results")
log_message(f"Query execution failed: {e}")
sys.exit()

always = (
True
if "always" in tree_report.keys() and tree_report["always"]
else False
)

if not always:
if not new_issues and not fixed_issues and not unstable_tests:
print(
f"No changes for {giturl} branch: {branch} (origin: {origin})"
)
continue
if not always and (
not new_issues and not fixed_issues and not unstable_tests
):
print(f"No changes for {giturl} branch: {branch} (origin: {origin})")
continue

build_status_group = group_status(checkout.build_status)
boot_status_group = group_status(checkout.boot_status)
Expand All @@ -513,14 +532,12 @@ def run_checkout_summary(
f"[STATUS] {tree_name}/{branch} - {record["git_commit_hash"]}"
)

default_recipients = tree_report.get("default_recipients", [])
specific_recipients = tree_report.get("recipients", [])
recipients = default_recipients + specific_recipients
report_options: list[PossibleReportOptions] = tree_report.get("options", [])
for option in report_options:
match option:
case "ignore_default_recipients":
recipients = specific_recipients
recipients = process_submission_options(
default_recipients=tree_report.get("default_recipients", []),
specific_recipients=tree_report.get("recipients", []),
options=tree_report.get("options", []),
)

email_args.tree_name = tree_name
msg_id = send_email_report(
service=service,
Expand Down
7 changes: 6 additions & 1 deletion backend/kernelCI_app/queries/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,9 @@ def kcidb_tests_results(
start_time DESC NULLS LAST;
"""

return kcidb_execute_query(query, params)
with connection.cursor() as cursor:
cursor.execute(query, params)
# TODO: check if it is possible to remove dict_fetchall.
# dict_fetchall has a performance impact and this query returns many rows,
# so they shouldn't be together
return dict_fetchall(cursor=cursor)
25 changes: 15 additions & 10 deletions backend/kernelCI_app/views/kciSummaryView.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ def get(self, request: HttpRequest):
&ti%7Ct={tree_name}
&o={origin}"""

new_issues, fixed_issues, unstable_tests = evaluate_test_results(
origin=origin,
giturl=git_url,
branch=git_branch,
commit_hash=commit_hash,
path=params.path,
interval="1 day",
group_size=params.group_size,
)

try:
new_issues, fixed_issues, unstable_tests = evaluate_test_results(
origin=origin,
giturl=git_url,
branch=git_branch,
commit_hash=commit_hash,
path=params.path,
interval="1 day",
group_size=params.group_size,
)

valid_response = KciSummaryResponse(
dashboard_url=dashboard_url,
git_url=git_url,
Expand All @@ -100,5 +100,10 @@ def get(self, request: HttpRequest):
)
except ValidationError as e:
return Response(data=e.json(), status=HTTPStatus.INTERNAL_SERVER_ERROR)
except Exception as e:
return create_api_error_response(
error_message=str(e),
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
)

return Response(valid_response.model_dump())