Skip to content

Commit fce51e8

Browse files
committed
Fix(cicd_bot): Actually inherit project level auto categorization config as per docs
1 parent eb174fd commit fce51e8

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

sqlmesh/core/config/root.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ def _normalize_identifiers(key: str) -> None:
256256
if self.physical_schema_mapping:
257257
_normalize_identifiers("physical_schema_mapping")
258258

259+
if self.cicd_bot and not self.cicd_bot.auto_categorize_changes_:
260+
# inherit the project-level auto_categorize_changes setting into the CICD bot if it has not been explicitly overridden
261+
self.cicd_bot.auto_categorize_changes_ = self.plan.auto_categorize_changes
262+
259263
return self
260264

261265
def get_default_test_connection(

sqlmesh/integrations/github/cicd/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class GithubCICDBotConfig(BaseConfig):
2222
enable_deploy_command: bool = False
2323
merge_method: t.Optional[MergeMethod] = None
2424
command_namespace: t.Optional[str] = None
25-
auto_categorize_changes: CategorizerConfig = CategorizerConfig.all_off()
25+
auto_categorize_changes_: t.Optional[CategorizerConfig] = Field(
26+
default=None, alias="auto_categorize_changes"
27+
)
2628
default_pr_start: t.Optional[TimeLike] = None
2729
skip_pr_backfill: bool = True
2830
pr_include_unmodified: t.Optional[bool] = None
@@ -49,6 +51,10 @@ def prod_branch_names(self) -> t.List[str]:
4951
return [self.prod_branch_names_]
5052
return ["main", "master"]
5153

54+
@property
55+
def auto_categorize_changes(self) -> CategorizerConfig:
56+
return self.auto_categorize_changes_ or CategorizerConfig.all_off()
57+
5258
FIELDS_FOR_ANALYTICS: t.ClassVar[t.Set[str]] = {
5359
"invalidate_environment_after_deploy",
5460
"enable_deploy_command",

tests/core/analytics/test_collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_on_cicd_command(collector: AnalyticsCollector, mocker: MockerFixture):
145145
{
146146
"seq_num": 1,
147147
"event_type": "CICD_COMMAND",
148-
"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}}',
148+
"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}}',
149149
**common_fields,
150150
}
151151
),

tests/integrations/github/cicd/test_config.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_load_yaml_config_default(tmp_path):
3434
assert config.cicd_bot.invalidate_environment_after_deploy
3535
assert config.cicd_bot.merge_method is None
3636
assert config.cicd_bot.command_namespace is None
37-
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off()
37+
assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes
3838
assert config.cicd_bot.default_pr_start is None
3939
assert not config.cicd_bot.enable_deploy_command
4040
assert config.cicd_bot.skip_pr_backfill
@@ -112,7 +112,7 @@ def test_load_python_config_defaults(tmp_path):
112112
assert config.cicd_bot.invalidate_environment_after_deploy
113113
assert config.cicd_bot.merge_method is None
114114
assert config.cicd_bot.command_namespace is None
115-
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off()
115+
assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes
116116
assert config.cicd_bot.default_pr_start is None
117117
assert not config.cicd_bot.enable_deploy_command
118118
assert config.cicd_bot.skip_pr_backfill
@@ -252,3 +252,24 @@ def test_ttl_in_past(tmp_path):
252252
match="TTL '1 week' is in the past. Please specify a relative time in the future. Ex: `in 1 week` instead of `1 week`.",
253253
):
254254
load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"])
255+
256+
257+
def test_auto_categorize_changes_inherits_from_project_config(tmp_path):
258+
(tmp_path / "config.yaml").write_text("""
259+
plan:
260+
auto_categorize_changes:
261+
external: off
262+
python: full
263+
sql: off
264+
seed: full
265+
266+
cicd_bot:
267+
type: github
268+
269+
model_defaults:
270+
dialect: duckdb
271+
""")
272+
273+
config = load_config_from_paths(Config, [tmp_path / "config.yaml"])
274+
275+
assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes

0 commit comments

Comments
 (0)