Skip to content

Commit d15446c

Browse files
authored
Fix: route linter warnings correctly in github output (#5441)
1 parent 15a0e10 commit d15446c

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

sqlmesh/core/console.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3641,7 +3641,10 @@ def show_linter_violations(
36413641
msg = f"\nLinter {severity} for `{model._path}`:\n{violations_msg}\n"
36423642

36433643
self._print(msg)
3644-
self._errors.append(msg)
3644+
if is_error:
3645+
self._errors.append(msg)
3646+
else:
3647+
self._warnings.append(msg)
36453648

36463649
@property
36473650
def captured_warnings(self) -> str:

tests/integrations/github/cicd/test_github_controller.py

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from sqlmesh.core.model import SqlModel
1616
from sqlmesh.core.user import User, UserRole
1717
from sqlmesh.core.plan.definition import Plan
18+
from sqlmesh.core.linter.rule import RuleViolation
1819
from sqlmesh.integrations.github.cicd.config import GithubCICDBotConfig, MergeMethod
1920
from sqlmesh.integrations.github.cicd.controller import (
2021
BotCommand,
@@ -29,6 +30,29 @@
2930

3031
pytestmark = pytest.mark.github
3132

33+
34+
def add_linter_violations(controller: GithubController):
35+
class _MockModel:
36+
_path = "tests/linter_test.sql"
37+
38+
class _MockLinterRule:
39+
name = "mock_linter_rule"
40+
41+
controller._console.show_linter_violations(
42+
[
43+
RuleViolation(
44+
rule=_MockLinterRule(), violation_msg="Linter warning", violation_range=None
45+
)
46+
],
47+
_MockModel(),
48+
)
49+
controller._console.show_linter_violations(
50+
[RuleViolation(rule=_MockLinterRule(), violation_msg="Linter error", violation_range=None)],
51+
_MockModel(),
52+
is_error=True,
53+
)
54+
55+
3256
github_controller_approvers_params = [
3357
(
3458
"2 approvers, 1 required",
@@ -660,12 +684,18 @@ def test_get_plan_summary_includes_warnings_and_errors(
660684
controller._console.log_warning("Warning 1\nWith multiline")
661685
controller._console.log_warning("Warning 2")
662686
controller._console.log_error("Error 1")
687+
add_linter_violations(controller)
663688

664689
summary = controller.get_plan_summary(controller.prod_plan)
665690

666-
assert ("> [!WARNING]\n>\n> - Warning 1\n> With multiline\n>\n> - Warning 2\n\n") in summary
667-
668-
assert ("> [!CAUTION]\n>\n> Error 1\n\n") in summary
691+
assert ("> [!WARNING]\n>\n> - Warning 1\n> With multiline\n>\n> - Warning 2\n>\n>") in summary
692+
assert (
693+
"> Linter warnings for `tests/linter_test.sql`:\n> - mock_linter_rule: Linter warning\n>"
694+
) in summary
695+
assert ("> [!CAUTION]\n>\n> - Error 1\n>\n>") in summary
696+
assert (
697+
"> Linter **errors** for `tests/linter_test.sql`:\n> - mock_linter_rule: Linter error\n>"
698+
) in summary
669699

670700

671701
def test_get_pr_environment_summary_includes_warnings_and_errors(
@@ -679,24 +709,39 @@ def test_get_pr_environment_summary_includes_warnings_and_errors(
679709

680710
controller._console.log_warning("Warning 1")
681711
controller._console.log_error("Error 1")
712+
add_linter_violations(controller)
682713

683714
# completed with no exception triggers a SUCCESS conclusion and only shows warnings
684715
success_summary = controller.get_pr_environment_summary(
685716
conclusion=GithubCheckConclusion.SUCCESS
686717
)
687-
assert "> [!WARNING]\n>\n> Warning 1\n" in success_summary
688-
assert "> [!CAUTION]\n>\n> Error 1" not in success_summary
718+
assert "> [!WARNING]\n>\n> - Warning 1\n" in success_summary
719+
assert (
720+
"> Linter warnings for `tests/linter_test.sql`:\n> - mock_linter_rule: Linter warning\n"
721+
in success_summary
722+
)
723+
assert "Error 1" not in success_summary
724+
assert "mock_linter_rule: Linter error" not in success_summary
689725

690726
# since they got consumed in the previous call
691727
controller._console.log_warning("Warning 1")
692728
controller._console.log_error("Error 1")
729+
add_linter_violations(controller)
693730

694731
# completed with an exception triggers a FAILED conclusion and shows errors
695732
error_summary = controller.get_pr_environment_summary(
696733
conclusion=GithubCheckConclusion.FAILURE, exception=SQLMeshError("Something broke")
697734
)
698-
assert "> [!WARNING]\n>\n> Warning 1\n" in error_summary
699-
assert "> [!CAUTION]\n>\n> Error 1" in error_summary
735+
assert "> [!WARNING]\n>\n> - Warning 1\n>\n" in error_summary
736+
assert (
737+
"> Linter warnings for `tests/linter_test.sql`:\n> - mock_linter_rule: Linter warning\n"
738+
in error_summary
739+
)
740+
assert "[!CAUTION]\n> <details>\n>\n> - Error 1\n>\n" in error_summary
741+
assert (
742+
"> Linter **errors** for `tests/linter_test.sql`:\n> - mock_linter_rule: Linter error\n"
743+
in error_summary
744+
)
700745

701746

702747
def test_pr_comment_deploy_indicator_includes_command_namespace(

0 commit comments

Comments
 (0)