Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sqlmesh/integrations/github/cicd/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
43 changes: 43 additions & 0 deletions tests/integrations/github/cicd/test_github_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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