Skip to content

Commit

Permalink
refactor(GitOpsConfig): PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
christiansiegel committed Jul 31, 2021
1 parent 4e22cae commit 804d41f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/commands/create-pr-preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Make sure that your *app repository* contains a `.gitops.config.yaml` file. This

1. find repository, branch, and folder containing the template
2. templates for host and namespace name
3. replacements in template files
3. replace values in template files
4. find repository and branch where the preview should be created (i.e. your *deployment config repository*)

```yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/create-preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Make sure that your *app repository* contains a `.gitops.config.yaml` file. This

1. find repository, branch, and folder containing the template
2. templates for host and namespace name
3. replacements in template files
3. replace values in template files
4. find repository and branch where the preview should be created (i.e. your *deployment config repository*)

```yaml
Expand Down
2 changes: 1 addition & 1 deletion gitopscli/commands/create_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __create_preview_from_template_if_not_existing(
def __replace_values(self, git_repo: GitRepo, gitops_config: GitOpsConfig) -> bool:
preview_id = self.__args.preview_id
preview_folder_name = gitops_config.get_preview_namespace(self.__args.preview_id)
context = GitOpsConfig.Replacement.Context(gitops_config, preview_id, self.__args.git_hash)
context = GitOpsConfig.Replacement.PreviewContext(gitops_config, preview_id, self.__args.git_hash)
any_value_replaced = False
for file, replacements in gitops_config.replacements.items():
for replacement in replacements:
Expand Down
6 changes: 3 additions & 3 deletions gitopscli/gitops_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
class GitOpsConfig:
class Replacement:
@dataclass(frozen=True)
class Context:
class PreviewContext:
gitops_config: "GitOpsConfig"
preview_id: str
git_hash: str

__VARIABLE_MAPPERS: Dict[str, Callable[["GitOpsConfig.Replacement.Context"], str]] = {
__VARIABLE_MAPPERS: Dict[str, Callable[["GitOpsConfig.Replacement.PreviewContext"], str]] = {
"GIT_HASH": lambda context: context.git_hash,
"PREVIEW_HOST": lambda context: context.gitops_config.get_preview_host(context.preview_id),
"PREVIEW_NAMESPACE": lambda context: context.gitops_config.get_preview_namespace(context.preview_id),
Expand All @@ -41,7 +41,7 @@ def __init__(self, path: str, value_template: str):
f"contains invalid variable: {var}"
)

def get_value(self, context: Context) -> str:
def get_value(self, context: PreviewContext) -> str:
val = self.value_template
for variable, value_func in self.__VARIABLE_MAPPERS.items():
val = val.replace(f"{{{variable}}}", value_func(context))
Expand Down

0 comments on commit 804d41f

Please sign in to comment.