Skip to content

Commit d1d8766

Browse files
authored
Fix!: Respect the project configuration if the forward-only suffix was not set in the bot's config (#5064)
1 parent cedaf88 commit d1d8766

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,11 @@ def pr_targets_prod_branch(self) -> bool:
479479

480480
@property
481481
def forward_only_plan(self) -> bool:
482+
default = self._context.config.plan.forward_only
482483
head_ref = self._pull_request.head.ref
483484
if isinstance(head_ref, str):
484-
return head_ref.endswith(self.bot_config.forward_only_branch_suffix)
485-
return False
485+
return head_ref.endswith(self.bot_config.forward_only_branch_suffix) or default
486+
return default
486487

487488
@classmethod
488489
def _append_output(cls, key: str, value: str) -> None:

tests/integrations/github/cicd/test_github_controller.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,3 +735,46 @@ def test_pr_comment_deploy_indicator_includes_command_namespace(
735735

736736
assert "To **apply** this PR's plan to prod, comment:\n - `/deploy`" not in comment
737737
assert "To **apply** this PR's plan to prod, comment:\n - `#SQLMesh/deploy`" in comment
738+
739+
740+
def test_forward_only_config_falls_back_to_plan_config(
741+
github_client,
742+
make_controller: t.Callable[..., GithubController],
743+
mocker: MockerFixture,
744+
):
745+
mock_repo = github_client.get_repo()
746+
mock_repo.create_check_run = mocker.MagicMock(
747+
side_effect=lambda **kwargs: make_mock_check_run(**kwargs)
748+
)
749+
750+
created_comments = []
751+
mock_issue = mock_repo.get_issue()
752+
mock_issue.create_comment = mocker.MagicMock(
753+
side_effect=lambda comment: make_mock_issue_comment(
754+
comment=comment, created_comments=created_comments
755+
)
756+
)
757+
mock_issue.get_comments = mocker.MagicMock(side_effect=lambda: created_comments)
758+
759+
mock_pull_request = mock_repo.get_pull()
760+
mock_pull_request.get_reviews = mocker.MagicMock(lambda: [])
761+
mock_pull_request.merged = False
762+
mock_pull_request.merge = mocker.MagicMock()
763+
mock_pull_request.head.ref = "unit-test-test-pr"
764+
765+
controller = make_controller(
766+
"tests/fixtures/github/pull_request_synchronized.json",
767+
github_client,
768+
bot_config=GithubCICDBotConfig(
769+
merge_method=MergeMethod.SQUASH,
770+
enable_deploy_command=True,
771+
forward_only_branch_suffix="-forward-only",
772+
),
773+
mock_out_context=False,
774+
)
775+
776+
controller._context.config.plan.forward_only = True
777+
assert controller.forward_only_plan
778+
779+
controller._context.config.plan.forward_only = False
780+
assert controller.forward_only_plan is False

0 commit comments

Comments
 (0)