sqlmesh.integrations.github.cicd.config
1import typing as t 2from enum import Enum 3 4from pydantic import Field 5 6from sqlmesh.core.config import CategorizerConfig 7from sqlmesh.core.config.base import BaseConfig 8from sqlmesh.utils.date import TimeLike 9from sqlmesh.utils.pydantic import model_validator 10from sqlmesh.core.console import get_console 11 12 13class MergeMethod(str, Enum): 14 MERGE = "merge" 15 SQUASH = "squash" 16 REBASE = "rebase" 17 18 19class GithubCICDBotConfig(BaseConfig): 20 type_: t.Literal["github"] = Field(alias="type", default="github") 21 22 invalidate_environment_after_deploy: bool = True 23 enable_deploy_command: bool = False 24 merge_method: t.Optional[MergeMethod] = None 25 command_namespace: t.Optional[str] = None 26 auto_categorize_changes_: t.Optional[CategorizerConfig] = Field( 27 default=None, alias="auto_categorize_changes" 28 ) 29 default_pr_start: t.Optional[TimeLike] = None 30 skip_pr_backfill_: t.Optional[bool] = Field(default=None, alias="skip_pr_backfill") 31 pr_include_unmodified_: t.Optional[bool] = Field(default=None, alias="pr_include_unmodified") 32 run_on_deploy_to_prod: bool = False 33 pr_environment_name: t.Optional[str] = None 34 pr_min_intervals: t.Optional[int] = None 35 prod_branch_names_: t.Optional[str] = Field(default=None, alias="prod_branch_name") 36 forward_only_branch_suffix_: t.Optional[str] = Field( 37 default=None, alias="forward_only_branch_suffix" 38 ) 39 check_if_blocked_on_deploy_to_prod: bool = True 40 41 @model_validator(mode="before") 42 @classmethod 43 def _validate(cls, data: t.Any) -> t.Any: 44 if not isinstance(data, dict): 45 return data 46 47 if data.get("enable_deploy_command") and not data.get("merge_method"): 48 raise ValueError("merge_method must be set if enable_deploy_command is True") 49 if data.get("command_namespace") and not data.get("enable_deploy_command"): 50 raise ValueError("enable_deploy_command must be set if command_namespace is set") 51 52 return data 53 54 @property 55 def prod_branch_names(self) -> t.List[str]: 56 if self.prod_branch_names_: 57 return [self.prod_branch_names_] 58 return ["main", "master"] 59 60 @property 61 def auto_categorize_changes(self) -> CategorizerConfig: 62 return self.auto_categorize_changes_ or CategorizerConfig.all_off() 63 64 @property 65 def pr_include_unmodified(self) -> bool: 66 return self.pr_include_unmodified_ or False 67 68 @property 69 def skip_pr_backfill(self) -> bool: 70 if self.skip_pr_backfill_ is None: 71 get_console().log_warning( 72 "`skip_pr_backfill` is unset, defaulting it to `true` (no data will be backfilled).\n" 73 "Future versions of SQLMesh will default to `skip_pr_backfill: false` to align with the CLI default behaviour.\n" 74 "If you would like to preserve the current behaviour and remove this warning, please explicitly set `skip_pr_backfill: true` in the bot config.\n\n" 75 "For more information on configuring the bot, see: https://sqlmesh.readthedocs.io/en/stable/integrations/github/" 76 ) 77 return True 78 return self.skip_pr_backfill_ 79 80 @property 81 def forward_only_branch_suffix(self) -> str: 82 return self.forward_only_branch_suffix_ or "-forward-only" 83 84 FIELDS_FOR_ANALYTICS: t.ClassVar[t.Set[str]] = { 85 "invalidate_environment_after_deploy", 86 "enable_deploy_command", 87 "merge_method", 88 "command_namespace", 89 "auto_categorize_changes", 90 "default_pr_start", 91 "skip_pr_backfill", 92 "pr_include_unmodified", 93 "run_on_deploy_to_prod", 94 "pr_min_intervals", 95 "forward_only_branch_suffix", 96 }
class
MergeMethod(builtins.str, enum.Enum):
An enumeration.
MERGE =
<MergeMethod.MERGE: 'merge'>
SQUASH =
<MergeMethod.SQUASH: 'squash'>
REBASE =
<MergeMethod.REBASE: 'rebase'>
Inherited Members
- enum.Enum
- name
- value
- builtins.str
- encode
- replace
- split
- rsplit
- join
- capitalize
- casefold
- title
- center
- count
- expandtabs
- find
- partition
- index
- ljust
- lower
- lstrip
- rfind
- rindex
- rjust
- rstrip
- rpartition
- splitlines
- strip
- swapcase
- translate
- upper
- startswith
- endswith
- removeprefix
- removesuffix
- isascii
- islower
- isupper
- istitle
- isspace
- isdecimal
- isdigit
- isnumeric
- isalpha
- isalnum
- isidentifier
- isprintable
- zfill
- format
- format_map
- maketrans
20class GithubCICDBotConfig(BaseConfig): 21 type_: t.Literal["github"] = Field(alias="type", default="github") 22 23 invalidate_environment_after_deploy: bool = True 24 enable_deploy_command: bool = False 25 merge_method: t.Optional[MergeMethod] = None 26 command_namespace: t.Optional[str] = None 27 auto_categorize_changes_: t.Optional[CategorizerConfig] = Field( 28 default=None, alias="auto_categorize_changes" 29 ) 30 default_pr_start: t.Optional[TimeLike] = None 31 skip_pr_backfill_: t.Optional[bool] = Field(default=None, alias="skip_pr_backfill") 32 pr_include_unmodified_: t.Optional[bool] = Field(default=None, alias="pr_include_unmodified") 33 run_on_deploy_to_prod: bool = False 34 pr_environment_name: t.Optional[str] = None 35 pr_min_intervals: t.Optional[int] = None 36 prod_branch_names_: t.Optional[str] = Field(default=None, alias="prod_branch_name") 37 forward_only_branch_suffix_: t.Optional[str] = Field( 38 default=None, alias="forward_only_branch_suffix" 39 ) 40 check_if_blocked_on_deploy_to_prod: bool = True 41 42 @model_validator(mode="before") 43 @classmethod 44 def _validate(cls, data: t.Any) -> t.Any: 45 if not isinstance(data, dict): 46 return data 47 48 if data.get("enable_deploy_command") and not data.get("merge_method"): 49 raise ValueError("merge_method must be set if enable_deploy_command is True") 50 if data.get("command_namespace") and not data.get("enable_deploy_command"): 51 raise ValueError("enable_deploy_command must be set if command_namespace is set") 52 53 return data 54 55 @property 56 def prod_branch_names(self) -> t.List[str]: 57 if self.prod_branch_names_: 58 return [self.prod_branch_names_] 59 return ["main", "master"] 60 61 @property 62 def auto_categorize_changes(self) -> CategorizerConfig: 63 return self.auto_categorize_changes_ or CategorizerConfig.all_off() 64 65 @property 66 def pr_include_unmodified(self) -> bool: 67 return self.pr_include_unmodified_ or False 68 69 @property 70 def skip_pr_backfill(self) -> bool: 71 if self.skip_pr_backfill_ is None: 72 get_console().log_warning( 73 "`skip_pr_backfill` is unset, defaulting it to `true` (no data will be backfilled).\n" 74 "Future versions of SQLMesh will default to `skip_pr_backfill: false` to align with the CLI default behaviour.\n" 75 "If you would like to preserve the current behaviour and remove this warning, please explicitly set `skip_pr_backfill: true` in the bot config.\n\n" 76 "For more information on configuring the bot, see: https://sqlmesh.readthedocs.io/en/stable/integrations/github/" 77 ) 78 return True 79 return self.skip_pr_backfill_ 80 81 @property 82 def forward_only_branch_suffix(self) -> str: 83 return self.forward_only_branch_suffix_ or "-forward-only" 84 85 FIELDS_FOR_ANALYTICS: t.ClassVar[t.Set[str]] = { 86 "invalidate_environment_after_deploy", 87 "enable_deploy_command", 88 "merge_method", 89 "command_namespace", 90 "auto_categorize_changes", 91 "default_pr_start", 92 "skip_pr_backfill", 93 "pr_include_unmodified", 94 "run_on_deploy_to_prod", 95 "pr_min_intervals", 96 "forward_only_branch_suffix", 97 }
Base configuration functionality for configuration classes.
merge_method: Optional[MergeMethod]
auto_categorize_changes_: Optional[sqlmesh.core.config.categorizer.CategorizerConfig]
auto_categorize_changes: sqlmesh.core.config.categorizer.CategorizerConfig
skip_pr_backfill: bool
69 @property 70 def skip_pr_backfill(self) -> bool: 71 if self.skip_pr_backfill_ is None: 72 get_console().log_warning( 73 "`skip_pr_backfill` is unset, defaulting it to `true` (no data will be backfilled).\n" 74 "Future versions of SQLMesh will default to `skip_pr_backfill: false` to align with the CLI default behaviour.\n" 75 "If you would like to preserve the current behaviour and remove this warning, please explicitly set `skip_pr_backfill: true` in the bot config.\n\n" 76 "For more information on configuring the bot, see: https://sqlmesh.readthedocs.io/en/stable/integrations/github/" 77 ) 78 return True 79 return self.skip_pr_backfill_
FIELDS_FOR_ANALYTICS: ClassVar[Set[str]] =
{'skip_pr_backfill', 'merge_method', 'invalidate_environment_after_deploy', 'run_on_deploy_to_prod', 'forward_only_branch_suffix', 'command_namespace', 'default_pr_start', 'pr_include_unmodified', 'pr_min_intervals', 'auto_categorize_changes', 'enable_deploy_command'}
model_config =
{'json_encoders': {<class 'sqlglot.expressions.core.Expr'>: <function _expression_encoder>, <class 'sqlglot.expressions.datatypes.DataType'>: <function _expression_encoder>, <class 'sqlglot.expressions.query.Tuple'>: <function _expression_encoder>, typing.Union[sqlglot.expressions.query.Query, sqlmesh.core.dialect.JinjaQuery]: <function _expression_encoder>, typing.Union[sqlglot.expressions.query.Query, sqlmesh.core.dialect.JinjaQuery, sqlmesh.core.dialect.MacroFunc]: <function _expression_encoder>, <class 'datetime.tzinfo'>: <function PydanticModel.<lambda>>}, 'arbitrary_types_allowed': True, 'extra': 'forbid', 'protected_namespaces': ()}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Inherited Members
- pydantic.main.BaseModel
- BaseModel
- model_fields
- model_computed_fields
- model_extra
- model_fields_set
- model_construct
- model_copy
- model_dump
- model_dump_json
- model_json_schema
- model_parametrized_name
- model_post_init
- model_rebuild
- model_validate
- model_validate_json
- model_validate_strings
- parse_file
- from_orm
- construct
- schema
- schema_json
- validate
- update_forward_refs