mirror of
https://gitlab.com/itsulu-odoo/runboat.git
synced 2026-05-30 23:41:27 +00:00
Some more typing
This commit is contained in:
parent
ac0bd848d4
commit
6020c9b25b
6 changed files with 39 additions and 20 deletions
|
|
@ -19,10 +19,26 @@ dependencies = [
|
|||
]
|
||||
dynamic = ["version", "description"]
|
||||
|
||||
[project.optional-dependencies]
|
||||
test = [
|
||||
"pytest",
|
||||
"pytest-cov",
|
||||
]
|
||||
mypy = [
|
||||
"mypy",
|
||||
"sqlalchemy[mypy]",
|
||||
"types-requests",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Home = "https://github.com/sbidoul/runboat"
|
||||
|
||||
[tool.isort]
|
||||
profile = 'black'
|
||||
|
||||
[tool.mypy]
|
||||
plugins = [
|
||||
"sqlalchemy.ext.mypy.plugin",
|
||||
]
|
||||
|
||||
# flake8 config is in .flake8
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ def stop(repo_id: str, branch_id: str, build_id: str):
|
|||
)
|
||||
def trigger_branch(org: str, repo: str, branch: str, db: Session = Depends(get_db)):
|
||||
branch_info = github.get_branch_info(org, repo, branch)
|
||||
branch = models.Branch.for_github_branch(db, branch_info)
|
||||
return models.Build.for_branch(db, branch, branch_info.head_sha)
|
||||
_branch = models.Branch.for_github_branch(db, branch_info)
|
||||
return models.Build.for_branch(db, _branch, branch_info.head_sha)
|
||||
|
||||
|
||||
@app.post(
|
||||
|
|
@ -127,5 +127,5 @@ def trigger_branch(org: str, repo: str, branch: str, db: Session = Depends(get_d
|
|||
)
|
||||
def trigger_pr(org: str, repo: str, pr: int, db: Session = Depends(get_db)):
|
||||
pr_info = github.get_pr_info(org, repo, pr)
|
||||
branch = models.Branch.for_github_pr(db, pr_info)
|
||||
return models.Build.for_branch(db, branch, pr_info.head_sha)
|
||||
_branch = models.Branch.for_github_pr(db, pr_info)
|
||||
return models.Build.for_branch(db, _branch, pr_info.head_sha)
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ app = FastAPI(title="Runboat")
|
|||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
async def startup() -> None:
|
||||
create_tables()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from typing import Generator
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
|
@ -9,11 +11,11 @@ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|||
Base = declarative_base()
|
||||
|
||||
|
||||
def create_tables():
|
||||
def create_tables() -> None:
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
|
||||
def get_db() -> Session:
|
||||
def get_db() -> Generator[Session]:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from typing import List
|
||||
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func
|
||||
from sqlalchemy.ext.compiler import compiles
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
from sqlalchemy.sql import expression
|
||||
|
||||
from .build_images import get_build_image
|
||||
from .db import Base, Session
|
||||
from .db import Base
|
||||
from .exceptions import RepoNotFound
|
||||
from .github import BranchInfo, PullRequestInfo
|
||||
from .settings import settings
|
||||
|
|
@ -28,7 +30,7 @@ class Repo(Base):
|
|||
org = Column(String, nullable=False)
|
||||
name = Column(String, nullable=False)
|
||||
|
||||
branches = relationship("Branch", back_populates="repo")
|
||||
branches: List["Branch"] = relationship("Branch", back_populates="repo")
|
||||
|
||||
@property
|
||||
def display_name(self) -> str:
|
||||
|
|
@ -62,13 +64,13 @@ class Branch(Base):
|
|||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
created = Column(DateTime, nullable=False, server_default=utcnow())
|
||||
target_branch = Column(String, nullable=False)
|
||||
target_branch: str = Column(String, nullable=False)
|
||||
pr = Column(Integer, nullable=True)
|
||||
|
||||
repo_id = Column(Integer, ForeignKey("repo.id"), nullable=False, index=True)
|
||||
|
||||
repo = relationship("Repo", back_populates="branches")
|
||||
builds = relationship("Build", back_populates="branch")
|
||||
repo: Repo = relationship(Repo, back_populates="branches")
|
||||
builds: List["Build"] = relationship("Build", back_populates="branch")
|
||||
|
||||
@property
|
||||
def display_name(self) -> str:
|
||||
|
|
@ -143,11 +145,11 @@ class Build(Base):
|
|||
created = Column(DateTime, nullable=False, server_default=utcnow())
|
||||
|
||||
branch_id = Column(Integer, ForeignKey("branch.id"), nullable=False, index=True)
|
||||
branch = relationship("Branch", back_populates="builds")
|
||||
branch: Branch = relationship(Branch, back_populates="builds")
|
||||
|
||||
build_image = Column(String, nullable=False)
|
||||
git_sha = Column(String, nullable=False)
|
||||
status = Column(String, nullable=False)
|
||||
git_sha: str = Column(String, nullable=False)
|
||||
status: str = Column(String, nullable=False)
|
||||
# ressource_label = Column(String, nullable=False, unique=True, index=True)
|
||||
|
||||
# TODO: add unique constraint on branch_id + git_sha
|
||||
|
|
@ -166,7 +168,6 @@ class Build(Base):
|
|||
|
||||
@classmethod
|
||||
def for_branch(cls, db: Session, branch: Branch, git_sha: str) -> "Build":
|
||||
print("*******", branch)
|
||||
build = (
|
||||
db.query(Build)
|
||||
.filter(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
def on_pr_open_or_update():
|
||||
def on_pr_open_or_update() -> None:
|
||||
# find Repo
|
||||
# find image from target branch (exit if not found)
|
||||
# find or create Branch
|
||||
|
|
@ -7,13 +7,13 @@ def on_pr_open_or_update():
|
|||
...
|
||||
|
||||
|
||||
def on_pr_close_or_merge():
|
||||
def on_pr_close_or_merge() -> None:
|
||||
# find Repo, Branch
|
||||
# delete branch (enqueue)
|
||||
...
|
||||
|
||||
|
||||
def on_push():
|
||||
def on_push() -> None:
|
||||
# find Repo, branch
|
||||
# find image from target branch (exit if not found)
|
||||
# find or create Branch
|
||||
|
|
|
|||
Loading…
Reference in a new issue