Skip to content
Merged
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: 3 additions & 1 deletion gitopscli/commands/add_pr_comment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dataclasses import dataclass

from gitopscli.git_api import GitApiConfig, GitRepoApiFactory
Expand All @@ -15,7 +17,7 @@ class Args(GitApiConfig):
parent_id: int | None
text: str

def __init__(self, args: Args) -> None:
def __init__(self, args: AddPrCommentCommand.Args) -> None:
self.__args = args

def execute(self) -> None:
Expand Down
4 changes: 3 additions & 1 deletion gitopscli/commands/create_pr_preview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dataclasses import dataclass

from gitopscli.git_api import GitApiConfig, GitRepoApiFactory
Expand All @@ -21,7 +23,7 @@ class Args(GitApiConfig):
pr_id: int
parent_id: int | None

def __init__(self, args: Args) -> None:
def __init__(self, args: CreatePrPreviewCommand.Args) -> None:
self.__args = args

def execute(self) -> None:
Expand Down
10 changes: 7 additions & 3 deletions gitopscli/commands/create_preview.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import logging
import shutil
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING, Any

from gitopscli.git_api import GitApiConfig, GitRepo, GitRepoApi, GitRepoApiFactory
from gitopscli.gitops_config import GitOpsConfig
Expand All @@ -13,6 +14,9 @@
from .command import Command
from .common import load_gitops_config

if TYPE_CHECKING:
from collections.abc import Callable


class CreatePreviewCommand(Command):
@dataclass(frozen=True)
Expand All @@ -29,7 +33,7 @@ class Args(GitApiConfig):
git_hash: str
preview_id: str

def __init__(self, args: Args) -> None:
def __init__(self, args: CreatePreviewCommand.Args) -> None:
self.__args = args
self.__deployment_already_up_to_date_callback: Callable[[str], None] = lambda _: None
self.__deployment_updated_callback: Callable[[str], None] = lambda _: None
Expand Down
4 changes: 3 additions & 1 deletion gitopscli/commands/delete_pr_preview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dataclasses import dataclass

from gitopscli.git_api import GitApiConfig
Expand All @@ -21,7 +23,7 @@ class Args(GitApiConfig):
branch: str
expect_preview_exists: bool

def __init__(self, args: Args) -> None:
def __init__(self, args: DeletePrPreviewCommand.Args) -> None:
self.__args = args

def execute(self) -> None:
Expand Down
9 changes: 7 additions & 2 deletions gitopscli/commands/delete_preview.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from __future__ import annotations

import logging
import shutil
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING

from gitopscli.git_api import GitApiConfig, GitRepo, GitRepoApi, GitRepoApiFactory
from gitopscli.gitops_config import GitOpsConfig
from gitopscli.gitops_exception import GitOpsException

from .command import Command
from .common import load_gitops_config

if TYPE_CHECKING:
from gitopscli.gitops_config import GitOpsConfig


class DeletePreviewCommand(Command):
@dataclass(frozen=True)
Expand All @@ -26,7 +31,7 @@ class Args(GitApiConfig):
preview_id: str
expect_preview_exists: bool

def __init__(self, args: Args) -> None:
def __init__(self, args: DeletePreviewCommand.Args) -> None:
self.__args = args

def execute(self) -> None:
Expand Down
4 changes: 3 additions & 1 deletion gitopscli/commands/deploy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import logging
import uuid
Expand Down Expand Up @@ -37,7 +39,7 @@ class Args(GitApiConfig):
merge_parameters: Any | None
merge_method: Literal["squash", "rebase", "merge"] = "merge"

def __init__(self, args: Args) -> None:
def __init__(self, args: DeployCommand.Args) -> None:
self.__args = args
self.__commit_hashes: list[str] = []

Expand Down
4 changes: 3 additions & 1 deletion gitopscli/commands/sync_apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging
from dataclasses import dataclass

Expand All @@ -24,7 +26,7 @@ class Args(GitApiConfig):
root_organisation: str
root_repository_name: str

def __init__(self, args: Args) -> None:
def __init__(self, args: SyncAppsCommand.Args) -> None:
self.__args = args

def execute(self) -> None:
Expand Down
4 changes: 3 additions & 1 deletion gitopscli/commands/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import importlib.metadata
from dataclasses import dataclass

Expand All @@ -9,7 +11,7 @@ class VersionCommand(Command):
class Args:
pass

def __init__(self, args: Args) -> None:
def __init__(self, args: VersionCommand.Args) -> None:
pass

def execute(self) -> None:
Expand Down
24 changes: 14 additions & 10 deletions gitopscli/gitops_config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

import hashlib
import re
from collections.abc import Callable
from dataclasses import dataclass
from string import Template
from typing import Any, ClassVar, cast
from typing import TYPE_CHECKING, Any, ClassVar, cast

from gitopscli.gitops_exception import GitOpsException

if TYPE_CHECKING:
from collections.abc import Callable

_VARIABLE_REGEX = re.compile(r"\${(\w+)}")


Expand All @@ -15,11 +19,11 @@ class GitOpsConfig:
class Replacement:
@dataclass(frozen=True)
class PreviewContext:
gitops_config: "GitOpsConfig"
gitops_config: GitOpsConfig
preview_id: str
git_hash: str

__VARIABLE_MAPPERS: ClassVar[dict[str, Callable[["GitOpsConfig.Replacement.PreviewContext"], str]]] = {
__VARIABLE_MAPPERS: ClassVar[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 @@ -44,7 +48,7 @@ def __init__(self, path: str, value_template: str) -> None:
f"contains invalid variable: {var}",
)

def get_value(self, context: PreviewContext) -> str:
def get_value(self, context: GitOpsConfig.Replacement.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 Expand Up @@ -162,16 +166,16 @@ def get_preview_namespace(self, preview_id: str) -> str:
raise GitOpsException(f"Invalid character in preview namespace: '{invalid_character[0]}'")
return preview_namespace

def get_created_message(self, context: Replacement.PreviewContext) -> str:
def get_created_message(self, context: GitOpsConfig.Replacement.PreviewContext) -> str:
return self.fill_template(self.messages_created_template, context)

def get_updated_message(self, context: Replacement.PreviewContext) -> str:
def get_updated_message(self, context: GitOpsConfig.Replacement.PreviewContext) -> str:
return self.fill_template(self.messages_updated_template, context)

def get_uptodate_message(self, context: Replacement.PreviewContext) -> str:
def get_uptodate_message(self, context: GitOpsConfig.Replacement.PreviewContext) -> str:
return self.fill_template(self.messages_uptodate_template, context)

def fill_template(self, template: str, context: Replacement.PreviewContext) -> str:
def fill_template(self, template: str, context: GitOpsConfig.Replacement.PreviewContext) -> str:
return Template(template).substitute(
APPLICATION_NAME=self.application_name,
PREVIEW_ID_HASH=self.create_preview_id_hash(context.preview_id),
Expand Down Expand Up @@ -213,7 +217,7 @@ def create_preview_id_hash_short(preview_id: str) -> str:
return GitOpsConfig.create_preview_id_hash(preview_id)[:3]

@staticmethod
def from_yaml(yaml: Any) -> "GitOpsConfig":
def from_yaml(yaml: Any) -> GitOpsConfig:
return _GitOpsConfigYamlParser(yaml).parse()


Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies = [
"pygithub",
"python-gitlab>=2.6.0,<3",
"azure-devops>=7,<8",
"typing_extensions>=4",
]

[project.urls]
Expand All @@ -27,7 +26,7 @@ test = [
"ruff",
"pytest-cov",
"ty",
"typeguard>=2.13.3,<3",
"typeguard>=2.13.3,<5",
"pre-commit",
]
docs = [
Expand Down
13 changes: 7 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.