@@ -1295,3 +1295,74 @@ def test_comment_command_deploy_prod_not_enabled(
12951295 with open (github_output_file , "r" , encoding = "utf-8" ) as f :
12961296 output = f .read ()
12971297 assert output == ""
1298+
1299+
1300+ def test_comment_command_deploy_prod_no_deploy_detected_yet (
1301+ github_client ,
1302+ make_controller ,
1303+ make_mock_check_run ,
1304+ make_mock_issue_comment ,
1305+ tmp_path : pathlib .Path ,
1306+ mocker : MockerFixture ,
1307+ ):
1308+ """
1309+ Scenario:
1310+ - PR is not merged
1311+ - No requred approvers defined
1312+ - Tests passed
1313+ - PR Merge Method defined
1314+ - Deploy command enabled but not yet triggered
1315+
1316+ Outcome:
1317+ - "Prod Environment Synced" step should explain the reason why it was skipped is because /deploy has not yet been detected
1318+ """
1319+ mock_repo = github_client .get_repo ()
1320+ mock_repo .create_check_run = mocker .MagicMock (
1321+ side_effect = lambda ** kwargs : make_mock_check_run (** kwargs )
1322+ )
1323+
1324+ created_comments = []
1325+ mock_issue = mock_repo .get_issue ()
1326+ mock_issue .create_comment = mocker .MagicMock (
1327+ side_effect = lambda comment : make_mock_issue_comment (
1328+ comment = comment , created_comments = created_comments
1329+ )
1330+ )
1331+ mock_issue .get_comments = mocker .MagicMock (side_effect = lambda : created_comments )
1332+
1333+ mock_pull_request = mock_repo .get_pull ()
1334+ mock_pull_request .get_reviews = mocker .MagicMock (lambda : [])
1335+ mock_pull_request .merged = False
1336+ mock_pull_request .merge = mocker .MagicMock ()
1337+
1338+ controller = make_controller (
1339+ "tests/fixtures/github/pull_request_synchronized.json" ,
1340+ github_client ,
1341+ bot_config = GithubCICDBotConfig (merge_method = MergeMethod .REBASE , enable_deploy_command = True ),
1342+ )
1343+ controller ._context ._run_tests = mocker .MagicMock (
1344+ side_effect = lambda ** kwargs : (TestResult (), "" )
1345+ )
1346+
1347+ github_output_file = tmp_path / "github_output.txt"
1348+
1349+ with mock .patch .dict (os .environ , {"GITHUB_OUTPUT" : str (github_output_file )}):
1350+ command ._run_all (controller )
1351+
1352+ assert "SQLMesh - Prod Plan Preview" in controller ._check_run_mapping
1353+ assert "SQLMesh - PR Environment Synced" in controller ._check_run_mapping
1354+ assert "SQLMesh - Prod Environment Synced" in controller ._check_run_mapping
1355+ assert "SQLMesh - Run Unit Tests" in controller ._check_run_mapping
1356+ prod_checks_runs = controller ._check_run_mapping ["SQLMesh - Prod Environment Synced" ].all_kwargs
1357+ assert len (prod_checks_runs ) == 2
1358+ assert GithubCheckStatus (prod_checks_runs [0 ]["status" ]).is_queued
1359+ assert GithubCheckStatus (prod_checks_runs [1 ]["status" ]).is_completed
1360+ assert prod_checks_runs [1 ]["output" ]["title" ] == "Skipped deployment"
1361+ assert (
1362+ prod_checks_runs [1 ]["output" ]["summary" ]
1363+ == "Skipped Deploying to Production because a `/deploy` command has not been detected yet"
1364+ )
1365+ assert GithubCheckConclusion (prod_checks_runs [1 ]["conclusion" ]).is_skipped
1366+
1367+ # required approvers are irrelevant because /deploy command is enabled
1368+ assert "SQLMesh - Has Required Approval" not in controller ._check_run_mapping
0 commit comments