1515from sqlmesh .core .model import SqlModel
1616from sqlmesh .core .user import User , UserRole
1717from sqlmesh .core .plan .definition import Plan
18+ from sqlmesh .core .linter .rule import RuleViolation
1819from sqlmesh .integrations .github .cicd .config import GithubCICDBotConfig , MergeMethod
1920from sqlmesh .integrations .github .cicd .controller import (
2021 BotCommand ,
2930
3031pytestmark = 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+
3256github_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\n With 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
671701def 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
702747def test_pr_comment_deploy_indicator_includes_command_namespace (
0 commit comments