-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For non-kernel artefacts, set due date to be today + 10 days (#154)
* For non-kernel artefacts, set due date to be today + 10 days * Move tests to the approprite file * Use context sensitive default instead of event listener
- Loading branch information
Showing
3 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ | |
# Written by: | ||
# Nadzeya Hutsko <[email protected]> | ||
# Omar Selo <[email protected]> | ||
from datetime import date, datetime | ||
|
||
from datetime import date, datetime, timedelta | ||
from typing import TypeVar | ||
|
||
from sqlalchemy import ( | ||
|
@@ -29,6 +30,7 @@ | |
UniqueConstraint, | ||
column, | ||
) | ||
from sqlalchemy.engine.default import DefaultExecutionContext | ||
from sqlalchemy.dialects.postgresql import ARRAY | ||
from sqlalchemy.orm import ( | ||
DeclarativeBase, | ||
|
@@ -37,6 +39,7 @@ | |
relationship, | ||
) | ||
from sqlalchemy.sql import func | ||
from sqlalchemy.ext.hybrid import hybrid_property | ||
|
||
from test_observer.data_access.models_enums import ( | ||
ArtefactStatus, | ||
|
@@ -77,6 +80,15 @@ def data_model_repr(obj: DataModel, *keys: str) -> str: | |
return f"{type(obj).__name__}({', '.join(kwargs)})" | ||
|
||
|
||
def determine_due_date(context: DefaultExecutionContext): | ||
name = context.get_current_parameters()["name"] | ||
is_kernel = name.startswith("linux-") or name.endswith("-kernel") | ||
if not is_kernel: | ||
# If not a kernel, return a date 10 days from now | ||
return date.today() + timedelta(days=10) | ||
return None | ||
|
||
|
||
class User(Base): | ||
""" | ||
ORM representing users that can be assigned to review artefacts | ||
|
@@ -148,7 +160,7 @@ class Artefact(Base): | |
assignee_id: Mapped[int | None] = mapped_column(ForeignKey("app_user.id")) | ||
assignee: Mapped[User | None] = relationship(back_populates="assignments") | ||
# Default fields | ||
due_date: Mapped[date | None] | ||
due_date: Mapped[date | None] = mapped_column(default=determine_due_date) | ||
status: Mapped[ArtefactStatus] = mapped_column(default=ArtefactStatus.UNDECIDED) | ||
bug_link: Mapped[str] = mapped_column(default="") | ||
|
||
|
@@ -186,6 +198,11 @@ def __repr__(self) -> str: | |
"status", | ||
) | ||
|
||
@hybrid_property | ||
def is_kernel(self) -> bool: | ||
"""Kernel artefacts start with 'linix-' or end with '-kernel'""" | ||
return self.name.startswith("linux-") or self.name.endswith("-kernel") | ||
|
||
|
||
class ArtefactBuild(Base): | ||
"""A model to represent specific builds of artefact (e.g. arm64 revision 2)""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters