Skip to content

Commit 82f2447

Browse files
authored
Feat(cicd_bot): Show models with uncategorized changes instead of a generic error (#4783)
1 parent 166ddb1 commit 82f2447

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

sqlmesh/integrations/github/cicd/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _update_pr_environment(controller: GithubController) -> bool:
116116
return conclusion is not None and conclusion.is_success
117117
except Exception as e:
118118
conclusion = controller.update_pr_environment_check(
119-
status=GithubCheckStatus.COMPLETED, exception=e
119+
status=GithubCheckStatus.COMPLETED, exception=e, plan=controller.pr_plan_or_none
120120
)
121121
return (
122122
conclusion is not None

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ def pr_plan(self) -> Plan:
408408
assert self._pr_plan_builder
409409
return self._pr_plan_builder.build()
410410

411+
@property
412+
def pr_plan_or_none(self) -> t.Optional[Plan]:
413+
try:
414+
return self.pr_plan
415+
except:
416+
return None
417+
411418
@property
412419
def prod_plan(self) -> Plan:
413420
if not self._prod_plan_builder:
@@ -823,6 +830,7 @@ def update_pr_environment_check(
823830
self,
824831
status: GithubCheckStatus,
825832
exception: t.Optional[Exception] = None,
833+
plan: t.Optional[Plan] = None,
826834
) -> t.Optional[GithubCheckConclusion]:
827835
"""
828836
Updates the status of the merge commit for the PR environment.
@@ -926,6 +934,14 @@ def conclusion_handler(
926934
if captured_errors:
927935
logger.debug(f"Captured errors: {captured_errors}")
928936
failure_msg = f"**Errors:**\n{captured_errors}\n"
937+
elif isinstance(exception, UncategorizedPlanError) and plan:
938+
failure_msg = f"The following models could not be categorized automatically:\n"
939+
for snapshot in plan.uncategorized:
940+
failure_msg += f"- {snapshot.name}\n"
941+
failure_msg += (
942+
f"\nRun `sqlmesh plan {self.pr_environment_name}` locally to apply these changes.\n\n"
943+
"If you would like the bot to automatically categorize changes, check the [documentation](https://sqlmesh.readthedocs.io/en/stable/integrations/github/) for more information."
944+
)
929945
elif isinstance(exception, PlanError):
930946
failure_msg = f"Plan application failed.\n\n{self._console.captured_output}"
931947
elif isinstance(exception, (SQLMeshError, SqlglotError, ValueError)):
@@ -940,11 +956,12 @@ def conclusion_handler(
940956
+ traceback.format_exc()
941957
)
942958
failure_msg = f"This is an unexpected error.\n\n**Exception:**\n```\n{traceback.format_exc()}\n```"
959+
943960
conclusion_to_summary = {
944961
GithubCheckConclusion.SKIPPED: f":next_track_button: Skipped creating or updating PR Environment `{self.pr_environment_name}`. {skip_reason}",
945962
GithubCheckConclusion.FAILURE: f":x: Failed to create or update PR Environment `{self.pr_environment_name}`.\n\n{failure_msg}",
946963
GithubCheckConclusion.CANCELLED: f":stop_sign: Cancelled creating or updating PR Environment `{self.pr_environment_name}`",
947-
GithubCheckConclusion.ACTION_REQUIRED: f":warning: Action Required to create or update PR Environment `{self.pr_environment_name}`. There are likely uncateogrized changes. Run `plan` locally to apply these changes. If you want the bot to automatically categorize changes, then check documentation (https://sqlmesh.readthedocs.io/en/stable/integrations/github/) for more information.",
964+
GithubCheckConclusion.ACTION_REQUIRED: f":warning: Action Required to create or update PR Environment `{self.pr_environment_name}` :warning:\n\n{failure_msg}",
948965
}
949966
summary = conclusion_to_summary.get(
950967
conclusion, f":interrobang: Got an unexpected conclusion: {conclusion.value}"

tests/integrations/github/cicd/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ def test_merge_pr_has_non_breaking_change_no_categorization(
665665
assert pr_checks_runs[2]["output"]["title"] == "PR Virtual Data Environment: hello_world_2"
666666
assert (
667667
pr_checks_runs[2]["output"]["summary"]
668-
== ":warning: Action Required to create or update PR Environment `hello_world_2`. There are likely uncateogrized changes. Run `plan` locally to apply these changes. If you want the bot to automatically categorize changes, then check documentation (https://sqlmesh.readthedocs.io/en/stable/integrations/github/) for more information."
668+
== """:warning: Action Required to create or update PR Environment `hello_world_2` :warning:\n\nThe following models could not be categorized automatically:\n- "memory"."sushi"."waiter_revenue_by_day"\n\nRun `sqlmesh plan hello_world_2` locally to apply these changes.\n\nIf you would like the bot to automatically categorize changes, check the [documentation](https://sqlmesh.readthedocs.io/en/stable/integrations/github/) for more information."""
669669
)
670670

671671
assert "SQLMesh - Prod Plan Preview" in controller._check_run_mapping

0 commit comments

Comments
 (0)