Remove Optional in favor of "| None" notation
Taking advange of latest pydantic features
This commit is contained in:
parent
bdcfa8872f
commit
65b0ebeeb4
4 changed files with 25 additions and 27 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
from typing import AsyncGenerator, Optional
|
from typing import AsyncGenerator
|
||||||
|
|
||||||
from ansi2html import Ansi2HTMLConverter
|
from ansi2html import Ansi2HTMLConverter
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||||
|
|
@ -46,7 +46,7 @@ class Build(BaseModel):
|
||||||
commit_info: github.CommitInfo
|
commit_info: github.CommitInfo
|
||||||
deploy_link: str
|
deploy_link: str
|
||||||
repo_target_branch_link: str
|
repo_target_branch_link: str
|
||||||
repo_pr_link: Optional[str]
|
repo_pr_link: str | None
|
||||||
repo_commit_link: str
|
repo_commit_link: str
|
||||||
webui_link: str
|
webui_link: str
|
||||||
status: models.BuildStatus
|
status: models.BuildStatus
|
||||||
|
|
@ -78,11 +78,11 @@ async def repos() -> list[models.Repo]:
|
||||||
response_model_exclude_none=True,
|
response_model_exclude_none=True,
|
||||||
)
|
)
|
||||||
async def builds(
|
async def builds(
|
||||||
repo: Optional[str] = None,
|
repo: str | None = None,
|
||||||
target_branch: Optional[str] = None,
|
target_branch: str | None = None,
|
||||||
branch: Optional[str] = None,
|
branch: str | None = None,
|
||||||
pr: Optional[int] = None,
|
pr: int | None = None,
|
||||||
status: Optional[models.BuildStatus] = None,
|
status: models.BuildStatus | None = None,
|
||||||
) -> list[models.Build]:
|
) -> list[models.Build]:
|
||||||
return list(
|
return list(
|
||||||
controller.db.search(
|
controller.db.search(
|
||||||
|
|
@ -96,10 +96,10 @@ async def builds(
|
||||||
dependencies=[Depends(authenticated)],
|
dependencies=[Depends(authenticated)],
|
||||||
)
|
)
|
||||||
async def undeploy_builds(
|
async def undeploy_builds(
|
||||||
repo: Optional[str] = None,
|
repo: str | None = None,
|
||||||
target_branch: Optional[str] = None,
|
target_branch: str | None = None,
|
||||||
branch: Optional[str] = None,
|
branch: str | None = None,
|
||||||
pr: Optional[int] = None,
|
pr: int | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
for build in controller.db.search(
|
for build in controller.db.search(
|
||||||
repo=repo, target_branch=target_branch, branch=branch, pr=pr
|
repo=repo, target_branch=target_branch, branch=branch, pr=pr
|
||||||
|
|
@ -254,11 +254,11 @@ class BuildEventSource:
|
||||||
@router.get("/build-events")
|
@router.get("/build-events")
|
||||||
async def build_events(
|
async def build_events(
|
||||||
request: Request,
|
request: Request,
|
||||||
repo: Optional[str] = None,
|
repo: str | None = None,
|
||||||
target_branch: Optional[str] = None,
|
target_branch: str | None = None,
|
||||||
branch: Optional[str] = None,
|
branch: str | None = None,
|
||||||
pr: Optional[int] = None,
|
pr: int | None = None,
|
||||||
build_name: Optional[str] = None,
|
build_name: str | None = None,
|
||||||
) -> EventSourceResponse:
|
) -> EventSourceResponse:
|
||||||
event_source = BuildEventSource(
|
event_source = BuildEventSource(
|
||||||
request, repo, target_branch, branch, pr, build_name
|
request, repo, target_branch, branch, pr, build_name
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Optional
|
from typing import Any
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
|
@ -26,7 +26,7 @@ async def _github_request(method: str, url: str, json: Any = None) -> Any:
|
||||||
class CommitInfo(BaseModel):
|
class CommitInfo(BaseModel):
|
||||||
repo: str
|
repo: str
|
||||||
target_branch: str
|
target_branch: str
|
||||||
pr: Optional[int]
|
pr: int | None
|
||||||
git_commit: str
|
git_commit: str
|
||||||
|
|
||||||
@validator("repo")
|
@validator("repo")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import re
|
import re
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from pydantic import BaseModel, BaseSettings, validator
|
from pydantic import BaseModel, BaseSettings, validator
|
||||||
|
|
||||||
|
|
@ -41,18 +40,18 @@ class Settings(BaseSettings):
|
||||||
# The wildcard domain where the builds will be reacheable.
|
# The wildcard domain where the builds will be reacheable.
|
||||||
build_domain: str
|
build_domain: str
|
||||||
# A dictionary of environment variables to set in the build container and jobs.
|
# A dictionary of environment variables to set in the build container and jobs.
|
||||||
build_env: Optional[dict[str, str]]
|
build_env: dict[str, str] | None
|
||||||
# A dictionary of secret environment variables to set in the build container and
|
# A dictionary of secret environment variables to set in the build container and
|
||||||
# jobs.
|
# jobs.
|
||||||
build_secret_env: Optional[dict[str, str]]
|
build_secret_env: dict[str, str] | None
|
||||||
# A dictionary of variables to be set in the jinja rendering context for the
|
# A dictionary of variables to be set in the jinja rendering context for the
|
||||||
# kubefiles.
|
# kubefiles.
|
||||||
build_template_vars: Optional[dict[str, str]]
|
build_template_vars: dict[str, str] | None
|
||||||
# The token to use for the GitHub api calls (to query branches and pull requests,
|
# The token to use for the GitHub api calls (to query branches and pull requests,
|
||||||
# and report build statuses).
|
# and report build statuses).
|
||||||
github_token: Optional[str]
|
github_token: str | None
|
||||||
# The file with the python logging configuration to use for the runboat controller.
|
# The file with the python logging configuration to use for the runboat controller.
|
||||||
log_config: Optional[str]
|
log_config: str | None
|
||||||
# The base url where the runboat UI and API is exposed on internet.
|
# The base url where the runboat UI and API is exposed on internet.
|
||||||
# Used to generate backlinks in GitHub statuses
|
# Used to generate backlinks in GitHub statuses
|
||||||
base_url: str = "http://localhost:8000"
|
base_url: str = "http://localhost:8000"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import shutil
|
import shutil
|
||||||
from importlib import resources
|
from importlib import resources
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
from fastapi import APIRouter, FastAPI, HTTPException, Response, status
|
from fastapi import APIRouter, FastAPI, HTTPException, Response, status
|
||||||
|
|
@ -58,7 +57,7 @@ def mount(app: FastAPI) -> None:
|
||||||
|
|
||||||
|
|
||||||
@router.get("/builds", response_class=RedirectResponse)
|
@router.get("/builds", response_class=RedirectResponse)
|
||||||
async def builds(repo: str, target_branch: Optional[str] = None) -> Response:
|
async def builds(repo: str, target_branch: str | None = None) -> Response:
|
||||||
url = f"/webui/builds.html?repo={repo}"
|
url = f"/webui/builds.html?repo={repo}"
|
||||||
if target_branch:
|
if target_branch:
|
||||||
url += f"&target_branch={target_branch}"
|
url += f"&target_branch={target_branch}"
|
||||||
|
|
@ -66,7 +65,7 @@ async def builds(repo: str, target_branch: Optional[str] = None) -> Response:
|
||||||
|
|
||||||
|
|
||||||
@router.get("/builds/{name}", response_class=RedirectResponse)
|
@router.get("/builds/{name}", response_class=RedirectResponse)
|
||||||
async def build(name: str, live: Optional[str] = None) -> Response:
|
async def build(name: str, live: str | None = None) -> Response:
|
||||||
build = controller.db.get(name)
|
build = controller.db.get(name)
|
||||||
if not build:
|
if not build:
|
||||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue