2929 format_intervals ,
3030)
3131from sqlmesh .core .user import User
32+ from sqlmesh .core .config import Config
3233from sqlmesh .integrations .github .cicd .config import GithubCICDBotConfig
3334from sqlmesh .utils import word_characters_only , Verbosity
3435from sqlmesh .utils .concurrency import NodeExecutionFailedError
3839 NoChangesPlanError ,
3940 PlanError ,
4041 UncategorizedPlanError ,
42+ LinterError ,
4143)
4244from sqlmesh .utils .pydantic import PydanticModel
4345
5052 from github .PullRequestReview import PullRequestReview
5153 from github .Repository import Repository
5254
53- from sqlmesh .core .config import Config
54-
5555logger = logging .getLogger (__name__ )
5656
5757
@@ -326,10 +326,7 @@ def __init__(
326326 if review .state .lower () == "approved"
327327 }
328328 logger .debug (f"Approvers: { ', ' .join (self ._approvers )} " )
329- self ._context : Context = Context (
330- paths = self ._paths ,
331- config = self .config ,
332- )
329+ self ._context : Context = Context (paths = self ._paths , config = self .config )
333330
334331 @property
335332 def deploy_command_enabled (self ) -> bool :
@@ -394,6 +391,7 @@ def pr_plan(self) -> Plan:
394391 self ._pr_plan_builder = self ._context .plan_builder (
395392 environment = self .pr_environment_name ,
396393 skip_tests = True ,
394+ skip_linter = True ,
397395 categorizer_config = self .bot_config .auto_categorize_changes ,
398396 start = self .bot_config .default_pr_start ,
399397 skip_backfill = self .bot_config .skip_pr_backfill ,
@@ -409,6 +407,7 @@ def prod_plan(self) -> Plan:
409407 c .PROD ,
410408 no_gaps = True ,
411409 skip_tests = True ,
410+ skip_linter = True ,
412411 categorizer_config = self .bot_config .auto_categorize_changes ,
413412 run = self .bot_config .run_on_deploy_to_prod ,
414413 )
@@ -423,6 +422,7 @@ def prod_plan_with_gaps(self) -> Plan:
423422 no_gaps = False ,
424423 no_auto_categorization = True ,
425424 skip_tests = True ,
425+ skip_linter = True ,
426426 run = self .bot_config .run_on_deploy_to_prod ,
427427 )
428428 assert self ._prod_plan_with_gaps_builder
@@ -478,6 +478,13 @@ def run_tests(self) -> t.Tuple[unittest.result.TestResult, str]:
478478 """
479479 return self ._context ._run_tests (verbosity = Verbosity .VERBOSE )
480480
481+ def run_linter (self ) -> None :
482+ """
483+ Run linter for the PR
484+ """
485+ self ._console .clear_captured_outputs ()
486+ self ._context .lint_models ()
487+
481488 def _get_or_create_comment (self , header : str = BOT_HEADER_MSG ) -> IssueComment :
482489 comment = seq_get (
483490 [comment for comment in self ._issue .get_comments () if header in comment .body ],
@@ -654,6 +661,37 @@ def _update_check_handler(
654661 full_summary = summary ,
655662 )
656663
664+ def update_linter_check (
665+ self ,
666+ status : GithubCheckStatus ,
667+ conclusion : t .Optional [GithubCheckConclusion ] = None ,
668+ ) -> None :
669+ if not self ._context .config .linter .enabled :
670+ return
671+
672+ def conclusion_handler (
673+ conclusion : GithubCheckConclusion ,
674+ ) -> t .Tuple [GithubCheckConclusion , str , t .Optional [str ]]:
675+ linter_summary = self ._console .consume_captured_output () or "Linter Success"
676+
677+ title = "Linter results"
678+
679+ return conclusion , title , linter_summary
680+
681+ self ._update_check_handler (
682+ check_name = "SQLMesh - Linter" ,
683+ status = status ,
684+ conclusion = conclusion ,
685+ status_handler = lambda status : (
686+ {
687+ GithubCheckStatus .IN_PROGRESS : "Running linter" ,
688+ GithubCheckStatus .QUEUED : "Waiting to Run linter" ,
689+ }[status ],
690+ None ,
691+ ),
692+ conclusion_handler = conclusion_handler ,
693+ )
694+
657695 def update_test_check (
658696 self ,
659697 status : GithubCheckStatus ,
@@ -751,7 +789,7 @@ def update_pr_environment_check(
751789 Updates the status of the merge commit for the PR environment.
752790 """
753791 conclusion : t .Optional [GithubCheckConclusion ] = None
754- if isinstance (exception , (NoChangesPlanError , TestFailure )):
792+ if isinstance (exception , (NoChangesPlanError , TestFailure , LinterError )):
755793 conclusion = GithubCheckConclusion .SKIPPED
756794 elif isinstance (exception , UncategorizedPlanError ):
757795 conclusion = GithubCheckConclusion .ACTION_REQUIRED
0 commit comments