Validate build settings at startup time

This commit is contained in:
Stéphane Bidoul 2021-11-24 23:32:25 +01:00
parent b34dd38a7b
commit 5e7919eaf4
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
2 changed files with 9 additions and 6 deletions

View file

@ -182,10 +182,6 @@ class Build(BaseModel):
build_settings = settings.get_build_settings( build_settings = settings.get_build_settings(
commit_info.repo, commit_info.target_branch commit_info.repo, commit_info.target_branch
) )
if len(build_settings) > 1:
raise NotImplementedError(
"Having more than one build per commit is not supported yet."
)
deployment_vars = k8s.make_deployment_vars( deployment_vars = k8s.make_deployment_vars(
k8s.DeploymentMode.deployment, k8s.DeploymentMode.deployment,
name, name,

View file

@ -1,8 +1,7 @@
import re import re
from typing import Optional from typing import Optional
from pydantic import BaseSettings from pydantic import BaseModel, BaseSettings, validator
from pydantic.main import BaseModel
from .exceptions import RepoOrBranchNotSupported from .exceptions import RepoOrBranchNotSupported
@ -16,6 +15,14 @@ class RepoSettings(BaseModel):
branch: str # regex branch: str # regex
builds: list[BuildSettings] builds: list[BuildSettings]
@validator("builds")
def validate_builds(cls, v: list[BuildSettings]) -> list[BuildSettings]:
if len(v) != 1:
raise ValueError(
"One and only one build settings is allowed per repo/branch entry."
)
return v
class Settings(BaseSettings): class Settings(BaseSettings):
# Configuration for supported repositories and branches. # Configuration for supported repositories and branches.