Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sqlmesh/core/config/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the name of the root validator no longer reflects its contents

# 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(
Expand Down
8 changes: 7 additions & 1 deletion sqlmesh/integrations/github/cicd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/core/analytics/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
),
Expand Down
25 changes: 23 additions & 2 deletions tests/integrations/github/cicd/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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