Skip to content

Commit 289993e

Browse files
authored
fix: CI/CD Bot exit early before applying plan on unmergeable PR (#5590)
1 parent aff61ae commit 289993e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,11 @@ def deploy_to_prod(self) -> None:
773773
"PR is already merged and this event was triggered prior to the merge."
774774
)
775775
merge_status = self._get_merge_state_status()
776+
if merge_status.is_blocked:
777+
raise CICDBotError(
778+
"Branch protection or ruleset requirement is likely not satisfied, e.g. missing CODEOWNERS approval. "
779+
"Please check PR and resolve any issues."
780+
)
776781
if merge_status.is_dirty:
777782
raise CICDBotError(
778783
"Merge commit cannot be cleanly created. Likely from a merge conflict. "

tests/integrations/github/cicd/test_github_controller.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,21 @@ def test_deploy_to_prod_merge_error(github_client, make_controller):
460460
controller.deploy_to_prod()
461461

462462

463+
def test_deploy_to_prod_blocked_pr(github_client, make_controller):
464+
mock_pull_request = github_client.get_repo().get_pull()
465+
mock_pull_request.merged = False
466+
controller = make_controller(
467+
"tests/fixtures/github/pull_request_synchronized.json",
468+
github_client,
469+
merge_state_status=MergeStateStatus.BLOCKED,
470+
)
471+
with pytest.raises(
472+
Exception,
473+
match=r"^Branch protection or ruleset requirement is likely not satisfied, e.g. missing CODEOWNERS approval.*",
474+
):
475+
controller.deploy_to_prod()
476+
477+
463478
def test_deploy_to_prod_dirty_pr(github_client, make_controller):
464479
mock_pull_request = github_client.get_repo().get_pull()
465480
mock_pull_request.merged = False
@@ -468,7 +483,10 @@ def test_deploy_to_prod_dirty_pr(github_client, make_controller):
468483
github_client,
469484
merge_state_status=MergeStateStatus.DIRTY,
470485
)
471-
with pytest.raises(Exception, match=r"^Merge commit cannot be cleanly created.*"):
486+
with pytest.raises(
487+
Exception,
488+
match=r"^Merge commit cannot be cleanly created. Likely from a merge conflict.*",
489+
):
472490
controller.deploy_to_prod()
473491

474492

0 commit comments

Comments
 (0)