Refactor get_build_settings
This commit is contained in:
parent
a090c6160e
commit
6912176be1
3 changed files with 27 additions and 16 deletions
|
|
@ -9,7 +9,7 @@ from pydantic import BaseModel
|
||||||
|
|
||||||
from . import github, k8s
|
from . import github, k8s
|
||||||
from .github import CommitInfo, GitHubStatusState
|
from .github import CommitInfo, GitHubStatusState
|
||||||
from .settings import get_build_settings, settings
|
from .settings import settings
|
||||||
from .utils import slugify
|
from .utils import slugify
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
@ -181,7 +181,9 @@ class Build(BaseModel):
|
||||||
name = f"b{uuid.uuid4()}"
|
name = f"b{uuid.uuid4()}"
|
||||||
slug = cls.make_slug(commit_info)
|
slug = cls.make_slug(commit_info)
|
||||||
_logger.info(f"Deploying {slug} ({name}).")
|
_logger.info(f"Deploying {slug} ({name}).")
|
||||||
build_settings = get_build_settings(commit_info.repo, commit_info.target_branch)
|
build_settings = settings.get_build_settings(
|
||||||
|
commit_info.repo, commit_info.target_branch
|
||||||
|
)
|
||||||
if len(build_settings) > 1:
|
if len(build_settings) > 1:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Having more than one build per commit is not supported yet."
|
"Having more than one build per commit is not supported yet."
|
||||||
|
|
|
||||||
|
|
@ -52,18 +52,27 @@ class Settings(BaseSettings):
|
||||||
# HTML fragment for second footer.
|
# HTML fragment for second footer.
|
||||||
additional_footer_html: str = ""
|
additional_footer_html: str = ""
|
||||||
|
|
||||||
class Config:
|
def get_build_settings(self, repo: str, target_branch: str) -> list[BuildSettings]:
|
||||||
env_prefix = "RUNBOAT_"
|
for repo_settings in self.repos:
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
|
||||||
|
|
||||||
|
|
||||||
def get_build_settings(repo: str, target_branch: str) -> list[BuildSettings]:
|
|
||||||
for repo_settings in settings.repos:
|
|
||||||
if not re.match(repo_settings.repo, repo, re.IGNORECASE):
|
if not re.match(repo_settings.repo, repo, re.IGNORECASE):
|
||||||
continue
|
continue
|
||||||
if not re.match(repo_settings.branch, target_branch):
|
if not re.match(repo_settings.branch, target_branch):
|
||||||
continue
|
continue
|
||||||
return repo_settings.builds
|
return repo_settings.builds
|
||||||
raise RepoOrBranchNotSupported(f"Branch {target_branch} of {repo} not supported.")
|
raise RepoOrBranchNotSupported(
|
||||||
|
f"Branch {target_branch} of {repo} not supported."
|
||||||
|
)
|
||||||
|
|
||||||
|
def is_repo_and_branch_supported(self, repo: str, target_branch: str) -> bool:
|
||||||
|
try:
|
||||||
|
self.get_build_settings(repo, target_branch)
|
||||||
|
except RepoOrBranchNotSupported:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
env_prefix = "RUNBOAT_"
|
||||||
|
|
||||||
|
|
||||||
|
settings = Settings()
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from runboat.exceptions import RepoOrBranchNotSupported
|
from runboat.exceptions import RepoOrBranchNotSupported
|
||||||
from runboat.settings import BuildSettings, get_build_settings
|
from runboat.settings import BuildSettings, settings
|
||||||
|
|
||||||
|
|
||||||
def test_get_build_settings() -> None:
|
def test_get_build_settings() -> None:
|
||||||
assert get_build_settings("OCA/mis-builder", "15.0") == [
|
assert settings.get_build_settings("OCA/mis-builder", "15.0") == [
|
||||||
BuildSettings(image="ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest")
|
BuildSettings(image="ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest")
|
||||||
]
|
]
|
||||||
with pytest.raises(RepoOrBranchNotSupported):
|
with pytest.raises(RepoOrBranchNotSupported):
|
||||||
get_build_settings("acsone/mis-builder", "15.0")
|
settings.get_build_settings("acsone/mis-builder", "15.0")
|
||||||
with pytest.raises(RepoOrBranchNotSupported):
|
with pytest.raises(RepoOrBranchNotSupported):
|
||||||
assert not get_build_settings("OCA/mis-builder", "15.0-stuff")
|
assert not settings.get_build_settings("OCA/mis-builder", "15.0-stuff")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue