29
29
format_intervals ,
30
30
)
31
31
from sqlmesh .core .user import User
32
+ from sqlmesh .core .config import Config
32
33
from sqlmesh .integrations .github .cicd .config import GithubCICDBotConfig
33
34
from sqlmesh .utils import word_characters_only , Verbosity
34
35
from sqlmesh .utils .concurrency import NodeExecutionFailedError
38
39
NoChangesPlanError ,
39
40
PlanError ,
40
41
UncategorizedPlanError ,
42
+ LinterError ,
41
43
)
42
44
from sqlmesh .utils .pydantic import PydanticModel
43
45
50
52
from github .PullRequestReview import PullRequestReview
51
53
from github .Repository import Repository
52
54
53
- from sqlmesh .core .config import Config
54
-
55
55
logger = logging .getLogger (__name__ )
56
56
57
57
@@ -326,10 +326,7 @@ def __init__(
326
326
if review .state .lower () == "approved"
327
327
}
328
328
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 )
333
330
334
331
@property
335
332
def deploy_command_enabled (self ) -> bool :
@@ -394,6 +391,7 @@ def pr_plan(self) -> Plan:
394
391
self ._pr_plan_builder = self ._context .plan_builder (
395
392
environment = self .pr_environment_name ,
396
393
skip_tests = True ,
394
+ skip_linter = True ,
397
395
categorizer_config = self .bot_config .auto_categorize_changes ,
398
396
start = self .bot_config .default_pr_start ,
399
397
skip_backfill = self .bot_config .skip_pr_backfill ,
@@ -409,6 +407,7 @@ def prod_plan(self) -> Plan:
409
407
c .PROD ,
410
408
no_gaps = True ,
411
409
skip_tests = True ,
410
+ skip_linter = True ,
412
411
categorizer_config = self .bot_config .auto_categorize_changes ,
413
412
run = self .bot_config .run_on_deploy_to_prod ,
414
413
)
@@ -423,6 +422,7 @@ def prod_plan_with_gaps(self) -> Plan:
423
422
no_gaps = False ,
424
423
no_auto_categorization = True ,
425
424
skip_tests = True ,
425
+ skip_linter = True ,
426
426
run = self .bot_config .run_on_deploy_to_prod ,
427
427
)
428
428
assert self ._prod_plan_with_gaps_builder
@@ -478,6 +478,13 @@ def run_tests(self) -> t.Tuple[unittest.result.TestResult, str]:
478
478
"""
479
479
return self ._context ._run_tests (verbosity = Verbosity .VERBOSE )
480
480
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
+
481
488
def _get_or_create_comment (self , header : str = BOT_HEADER_MSG ) -> IssueComment :
482
489
comment = seq_get (
483
490
[comment for comment in self ._issue .get_comments () if header in comment .body ],
@@ -654,6 +661,37 @@ def _update_check_handler(
654
661
full_summary = summary ,
655
662
)
656
663
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
+
657
695
def update_test_check (
658
696
self ,
659
697
status : GithubCheckStatus ,
@@ -751,7 +789,7 @@ def update_pr_environment_check(
751
789
Updates the status of the merge commit for the PR environment.
752
790
"""
753
791
conclusion : t .Optional [GithubCheckConclusion ] = None
754
- if isinstance (exception , (NoChangesPlanError , TestFailure )):
792
+ if isinstance (exception , (NoChangesPlanError , TestFailure , LinterError )):
755
793
conclusion = GithubCheckConclusion .SKIPPED
756
794
elif isinstance (exception , UncategorizedPlanError ):
757
795
conclusion = GithubCheckConclusion .ACTION_REQUIRED
0 commit comments