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 default_pr_preview_start: TimeLike = "yesterday" 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 pr_preview_min_intervals: int = Field(default=1, ge=0) 37 prod_branch_names_: t.Optional[str] = Field(default=None, alias="prod_branch_name") 38 forward_only_branch_suffix_: t.Optional[str] = Field( 39 default=None, alias="forward_only_branch_suffix" 40 ) 41 check_if_blocked_on_deploy_to_prod: bool = True 42 43 @model_validator(mode="before") 44 @classmethod 45 def _validate(cls, data: t.Any) -> t.Any: 46 if not isinstance(data, dict): 47 return data 48 49 if data.get("enable_deploy_command") and not data.get("merge_method"): 50 raise ValueError("merge_method must be set if enable_deploy_command is True") 51 if data.get("command_namespace") and not data.get("enable_deploy_command"): 52 raise ValueError("enable_deploy_command must be set if command_namespace is set") 53 54 return data 55 56 @property 57 def prod_branch_names(self) -> t.List[str]: 58 if self.prod_branch_names_: 59 return [self.prod_branch_names_] 60 return ["main", "master"] 61 62 @property 63 def auto_categorize_changes(self) -> CategorizerConfig: 64 return self.auto_categorize_changes_ or CategorizerConfig.all_off() 65 66 @property 67 def pr_include_unmodified(self) -> bool: 68 return self.pr_include_unmodified_ or False 69 70 @property 71 def skip_pr_backfill(self) -> bool: 72 if self.skip_pr_backfill_ is None: 73 get_console().log_warning( 74 "`skip_pr_backfill` is unset, defaulting it to `true` (no data will be backfilled).\n" 75 "Future versions of SQLMesh will default to `skip_pr_backfill: false` to align with the CLI default behaviour.\n" 76 "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" 77 "For more information on configuring the bot, see: https://sqlmesh.readthedocs.io/en/stable/integrations/github/" 78 ) 79 return True 80 return self.skip_pr_backfill_ 81 82 @property 83 def forward_only_branch_suffix(self) -> str: 84 return self.forward_only_branch_suffix_ or "-forward-only" 85 86 FIELDS_FOR_ANALYTICS: t.ClassVar[t.Set[str]] = { 87 "invalidate_environment_after_deploy", 88 "enable_deploy_command", 89 "merge_method", 90 "command_namespace", 91 "auto_categorize_changes", 92 "default_pr_start", 93 "default_pr_preview_start", 94 "skip_pr_backfill", 95 "pr_include_unmodified", 96 "run_on_deploy_to_prod", 97 "pr_min_intervals", 98 "pr_preview_min_intervals", 99 "forward_only_branch_suffix", 100 }
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 default_pr_preview_start: TimeLike = "yesterday" 32 skip_pr_backfill_: t.Optional[bool] = Field(default=None, alias="skip_pr_backfill") 33 pr_include_unmodified_: t.Optional[bool] = Field(default=None, alias="pr_include_unmodified") 34 run_on_deploy_to_prod: bool = False 35 pr_environment_name: t.Optional[str] = None 36 pr_min_intervals: t.Optional[int] = None 37 pr_preview_min_intervals: int = Field(default=1, ge=0) 38 prod_branch_names_: t.Optional[str] = Field(default=None, alias="prod_branch_name") 39 forward_only_branch_suffix_: t.Optional[str] = Field( 40 default=None, alias="forward_only_branch_suffix" 41 ) 42 check_if_blocked_on_deploy_to_prod: bool = True 43 44 @model_validator(mode="before") 45 @classmethod 46 def _validate(cls, data: t.Any) -> t.Any: 47 if not isinstance(data, dict): 48 return data 49 50 if data.get("enable_deploy_command") and not data.get("merge_method"): 51 raise ValueError("merge_method must be set if enable_deploy_command is True") 52 if data.get("command_namespace") and not data.get("enable_deploy_command"): 53 raise ValueError("enable_deploy_command must be set if command_namespace is set") 54 55 return data 56 57 @property 58 def prod_branch_names(self) -> t.List[str]: 59 if self.prod_branch_names_: 60 return [self.prod_branch_names_] 61 return ["main", "master"] 62 63 @property 64 def auto_categorize_changes(self) -> CategorizerConfig: 65 return self.auto_categorize_changes_ or CategorizerConfig.all_off() 66 67 @property 68 def pr_include_unmodified(self) -> bool: 69 return self.pr_include_unmodified_ or False 70 71 @property 72 def skip_pr_backfill(self) -> bool: 73 if self.skip_pr_backfill_ is None: 74 get_console().log_warning( 75 "`skip_pr_backfill` is unset, defaulting it to `true` (no data will be backfilled).\n" 76 "Future versions of SQLMesh will default to `skip_pr_backfill: false` to align with the CLI default behaviour.\n" 77 "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" 78 "For more information on configuring the bot, see: https://sqlmesh.readthedocs.io/en/stable/integrations/github/" 79 ) 80 return True 81 return self.skip_pr_backfill_ 82 83 @property 84 def forward_only_branch_suffix(self) -> str: 85 return self.forward_only_branch_suffix_ or "-forward-only" 86 87 FIELDS_FOR_ANALYTICS: t.ClassVar[t.Set[str]] = { 88 "invalidate_environment_after_deploy", 89 "enable_deploy_command", 90 "merge_method", 91 "command_namespace", 92 "auto_categorize_changes", 93 "default_pr_start", 94 "default_pr_preview_start", 95 "skip_pr_backfill", 96 "pr_include_unmodified", 97 "run_on_deploy_to_prod", 98 "pr_min_intervals", 99 "pr_preview_min_intervals", 100 "forward_only_branch_suffix", 101 }
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
71 @property 72 def skip_pr_backfill(self) -> bool: 73 if self.skip_pr_backfill_ is None: 74 get_console().log_warning( 75 "`skip_pr_backfill` is unset, defaulting it to `true` (no data will be backfilled).\n" 76 "Future versions of SQLMesh will default to `skip_pr_backfill: false` to align with the CLI default behaviour.\n" 77 "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" 78 "For more information on configuring the bot, see: https://sqlmesh.readthedocs.io/en/stable/integrations/github/" 79 ) 80 return True 81 return self.skip_pr_backfill_
FIELDS_FOR_ANALYTICS: ClassVar[Set[str]] =
{'auto_categorize_changes', 'pr_include_unmodified', 'default_pr_start', 'skip_pr_backfill', 'pr_min_intervals', 'merge_method', 'default_pr_preview_start', 'run_on_deploy_to_prod', 'pr_preview_min_intervals', 'forward_only_branch_suffix', 'command_namespace', 'enable_deploy_command', 'invalidate_environment_after_deploy'}
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