diff --git a/sqlmesh/integrations/github/cicd/controller.py b/sqlmesh/integrations/github/cicd/controller.py index cc1131deff..dd5ee70e76 100644 --- a/sqlmesh/integrations/github/cicd/controller.py +++ b/sqlmesh/integrations/github/cicd/controller.py @@ -479,10 +479,11 @@ def pr_targets_prod_branch(self) -> bool: @property def forward_only_plan(self) -> bool: + default = self._context.config.plan.forward_only head_ref = self._pull_request.head.ref if isinstance(head_ref, str): - return head_ref.endswith(self.bot_config.forward_only_branch_suffix) - return False + return head_ref.endswith(self.bot_config.forward_only_branch_suffix) or default + return default @classmethod def _append_output(cls, key: str, value: str) -> None: diff --git a/tests/integrations/github/cicd/test_github_controller.py b/tests/integrations/github/cicd/test_github_controller.py index f1be97ee20..a27f75f459 100644 --- a/tests/integrations/github/cicd/test_github_controller.py +++ b/tests/integrations/github/cicd/test_github_controller.py @@ -735,3 +735,46 @@ def test_pr_comment_deploy_indicator_includes_command_namespace( assert "To **apply** this PR's plan to prod, comment:\n - `/deploy`" not in comment assert "To **apply** this PR's plan to prod, comment:\n - `#SQLMesh/deploy`" in comment + + +def test_forward_only_config_falls_back_to_plan_config( + github_client, + make_controller: t.Callable[..., GithubController], + mocker: MockerFixture, +): + mock_repo = github_client.get_repo() + mock_repo.create_check_run = mocker.MagicMock( + side_effect=lambda **kwargs: make_mock_check_run(**kwargs) + ) + + created_comments = [] + mock_issue = mock_repo.get_issue() + mock_issue.create_comment = mocker.MagicMock( + side_effect=lambda comment: make_mock_issue_comment( + comment=comment, created_comments=created_comments + ) + ) + mock_issue.get_comments = mocker.MagicMock(side_effect=lambda: created_comments) + + mock_pull_request = mock_repo.get_pull() + mock_pull_request.get_reviews = mocker.MagicMock(lambda: []) + mock_pull_request.merged = False + mock_pull_request.merge = mocker.MagicMock() + mock_pull_request.head.ref = "unit-test-test-pr" + + controller = make_controller( + "tests/fixtures/github/pull_request_synchronized.json", + github_client, + bot_config=GithubCICDBotConfig( + merge_method=MergeMethod.SQUASH, + enable_deploy_command=True, + forward_only_branch_suffix="-forward-only", + ), + mock_out_context=False, + ) + + controller._context.config.plan.forward_only = True + assert controller.forward_only_plan + + controller._context.config.plan.forward_only = False + assert controller.forward_only_plan is False