From fce51e8d576e53f37fc6c8ea5cf808dec47c5c1f Mon Sep 17 00:00:00 2001 From: Erin Drummond Date: Mon, 23 Jun 2025 23:12:26 +0000 Subject: [PATCH] Fix(cicd_bot): Actually inherit project level auto categorization config as per docs --- sqlmesh/core/config/root.py | 4 +++ sqlmesh/integrations/github/cicd/config.py | 8 +++++- tests/core/analytics/test_collector.py | 2 +- tests/integrations/github/cicd/test_config.py | 25 +++++++++++++++++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/sqlmesh/core/config/root.py b/sqlmesh/core/config/root.py index a8b8a2a797..5e15db0132 100644 --- a/sqlmesh/core/config/root.py +++ b/sqlmesh/core/config/root.py @@ -256,6 +256,10 @@ def _normalize_identifiers(key: str) -> None: if self.physical_schema_mapping: _normalize_identifiers("physical_schema_mapping") + if self.cicd_bot and not self.cicd_bot.auto_categorize_changes_: + # inherit the project-level auto_categorize_changes setting into the CICD bot if it has not been explicitly overridden + self.cicd_bot.auto_categorize_changes_ = self.plan.auto_categorize_changes + return self def get_default_test_connection( diff --git a/sqlmesh/integrations/github/cicd/config.py b/sqlmesh/integrations/github/cicd/config.py index b273329380..47a14b562d 100644 --- a/sqlmesh/integrations/github/cicd/config.py +++ b/sqlmesh/integrations/github/cicd/config.py @@ -22,7 +22,9 @@ class GithubCICDBotConfig(BaseConfig): enable_deploy_command: bool = False merge_method: t.Optional[MergeMethod] = None command_namespace: t.Optional[str] = None - auto_categorize_changes: CategorizerConfig = CategorizerConfig.all_off() + auto_categorize_changes_: t.Optional[CategorizerConfig] = Field( + default=None, alias="auto_categorize_changes" + ) default_pr_start: t.Optional[TimeLike] = None skip_pr_backfill: bool = True pr_include_unmodified: t.Optional[bool] = None @@ -49,6 +51,10 @@ def prod_branch_names(self) -> t.List[str]: return [self.prod_branch_names_] return ["main", "master"] + @property + def auto_categorize_changes(self) -> CategorizerConfig: + return self.auto_categorize_changes_ or CategorizerConfig.all_off() + FIELDS_FOR_ANALYTICS: t.ClassVar[t.Set[str]] = { "invalidate_environment_after_deploy", "enable_deploy_command", diff --git a/tests/core/analytics/test_collector.py b/tests/core/analytics/test_collector.py index 957db3a003..59e7e37dba 100644 --- a/tests/core/analytics/test_collector.py +++ b/tests/core/analytics/test_collector.py @@ -145,7 +145,7 @@ def test_on_cicd_command(collector: AnalyticsCollector, mocker: MockerFixture): { "seq_num": 1, "event_type": "CICD_COMMAND", - "event": '{"command_name": "test_cicd", "command_args": ["arg_1", "arg_2"], "parent_command_names": ["parent_a", "parent_b"], "cicd_bot_config": {"invalidate_environment_after_deploy": true, "enable_deploy_command": false, "auto_categorize_changes": {"external": "off", "python": "off", "sql": "off", "seed": "off"}, "skip_pr_backfill": true, "run_on_deploy_to_prod": false}}', + "event": '{"command_name": "test_cicd", "command_args": ["arg_1", "arg_2"], "parent_command_names": ["parent_a", "parent_b"], "cicd_bot_config": {"invalidate_environment_after_deploy": true, "enable_deploy_command": false, "skip_pr_backfill": true, "run_on_deploy_to_prod": false}}', **common_fields, } ), diff --git a/tests/integrations/github/cicd/test_config.py b/tests/integrations/github/cicd/test_config.py index d42a5bdb4f..126e12c5c9 100644 --- a/tests/integrations/github/cicd/test_config.py +++ b/tests/integrations/github/cicd/test_config.py @@ -34,7 +34,7 @@ def test_load_yaml_config_default(tmp_path): assert config.cicd_bot.invalidate_environment_after_deploy assert config.cicd_bot.merge_method is None assert config.cicd_bot.command_namespace is None - assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off() + assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes assert config.cicd_bot.default_pr_start is None assert not config.cicd_bot.enable_deploy_command assert config.cicd_bot.skip_pr_backfill @@ -112,7 +112,7 @@ def test_load_python_config_defaults(tmp_path): assert config.cicd_bot.invalidate_environment_after_deploy assert config.cicd_bot.merge_method is None assert config.cicd_bot.command_namespace is None - assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off() + assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes assert config.cicd_bot.default_pr_start is None assert not config.cicd_bot.enable_deploy_command assert config.cicd_bot.skip_pr_backfill @@ -252,3 +252,24 @@ def test_ttl_in_past(tmp_path): match="TTL '1 week' is in the past. Please specify a relative time in the future. Ex: `in 1 week` instead of `1 week`.", ): load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"]) + + +def test_auto_categorize_changes_inherits_from_project_config(tmp_path): + (tmp_path / "config.yaml").write_text(""" +plan: + auto_categorize_changes: + external: off + python: full + sql: off + seed: full + +cicd_bot: + type: github + +model_defaults: + dialect: duckdb +""") + + config = load_config_from_paths(Config, [tmp_path / "config.yaml"]) + + assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes