builds.html: add builds oldest first
So new builds being created appear left or top.
This commit is contained in:
parent
4e9872bfed
commit
7a4e188a7e
4 changed files with 54 additions and 7 deletions
|
|
@ -11,6 +11,7 @@ from starlette.status import HTTP_404_NOT_FOUND
|
|||
|
||||
from . import github, models
|
||||
from .controller import Controller, controller
|
||||
from .db import SortOrder
|
||||
from .deps import authenticated
|
||||
|
||||
router = APIRouter()
|
||||
|
|
@ -239,6 +240,7 @@ class BuildEventSource:
|
|||
branch=self.branch,
|
||||
pr=self.pr,
|
||||
name=self.build_name,
|
||||
sort=SortOrder.asc,
|
||||
):
|
||||
yield self._serialize(models.BuildEvent.modified, build)
|
||||
while True:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import sqlite3
|
||||
from enum import Enum
|
||||
from typing import Iterator, Protocol, cast
|
||||
from weakref import WeakSet
|
||||
|
||||
|
|
@ -8,6 +9,13 @@ from .models import Build, BuildEvent, BuildInitStatus, BuildStatus, Repo
|
|||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SortOrder(Enum):
|
||||
# commits of pr, then commits of branches, oldest first
|
||||
asc = 1
|
||||
# commit os branches, then commits of prs, newest first
|
||||
desc = 2
|
||||
|
||||
|
||||
class BuildListener(Protocol):
|
||||
def on_build_event(self, event: BuildEvent, build: Build) -> None:
|
||||
...
|
||||
|
|
@ -195,6 +203,7 @@ class BuildsDb:
|
|||
branch: str | None = None,
|
||||
pr: int | None = None,
|
||||
name: str | None = None,
|
||||
sort: SortOrder = SortOrder.desc,
|
||||
) -> Iterator[Build]:
|
||||
query = "SELECT * FROM builds "
|
||||
where = []
|
||||
|
|
@ -217,10 +226,22 @@ class BuildsDb:
|
|||
params.append(name)
|
||||
if where:
|
||||
query += "WHERE " + " AND ".join(where)
|
||||
query += (
|
||||
" ORDER BY"
|
||||
" repo, target_branch DESC, COALESCE(pr, 999999) DESC, created DESC"
|
||||
)
|
||||
if sort == SortOrder.desc:
|
||||
query += (
|
||||
" ORDER BY"
|
||||
" repo DESC,"
|
||||
" COALESCE(pr, 999999) DESC,"
|
||||
" target_branch DESC,"
|
||||
" created DESC"
|
||||
)
|
||||
elif sort == SortOrder.asc:
|
||||
query += (
|
||||
" ORDER BY"
|
||||
" repo ASC,"
|
||||
" COALESCE(pr, 999999) ASC,"
|
||||
" target_branch ASC,"
|
||||
" created ASC"
|
||||
)
|
||||
rows = self._con.execute(query, params).fetchall()
|
||||
for row in rows:
|
||||
yield self._build_from_row(row)
|
||||
|
|
|
|||
|
|
@ -43,13 +43,14 @@
|
|||
rowElement = document.createElement("div");
|
||||
rowElement.classList.add("row");
|
||||
rowElement.id = rowId;
|
||||
document.getElementById("builds").appendChild(rowElement);
|
||||
const buildsElement = document.getElementById("builds");
|
||||
buildsElement.insertBefore(rowElement, buildsElement.firstChild);
|
||||
}
|
||||
// add build element to row
|
||||
buildElement = document.createElement("runboat-build");
|
||||
buildElement.id = oEvent.build.name;
|
||||
buildElement.build = oEvent.build;
|
||||
rowElement.appendChild(buildElement);
|
||||
rowElement.insertBefore(buildElement, rowElement.firstChild);
|
||||
}
|
||||
} else if (oEvent.event == "del") {
|
||||
const buildElement = document.getElementById(oEvent.build.name);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from runboat.db import BuildsDb
|
||||
from runboat.db import BuildsDb, SortOrder
|
||||
from runboat.models import Build, BuildInitStatus, BuildStatus, Repo
|
||||
|
||||
|
||||
|
|
@ -94,6 +94,29 @@ def test_search_by_branch_and_pr() -> None:
|
|||
assert list(db.search(pr=1)) == [build2]
|
||||
|
||||
|
||||
def test_search_sort() -> None:
|
||||
db = BuildsDb()
|
||||
db.add(build1 := _make_build(name="b1", target_branch="15.0", pr=None))
|
||||
db.add(build2 := _make_build(name="b2", target_branch="15.0", pr=1))
|
||||
db.add(build3 := _make_build(name="b3", target_branch="14.0", pr=None))
|
||||
db.add(build4 := _make_build(name="b4", target_branch="14.0", pr=2))
|
||||
db.add(build5 := _make_build(name="b5", target_branch="10.0", pr=3))
|
||||
assert [b.name for b in db.search(sort=SortOrder.asc)] == [
|
||||
build2.name,
|
||||
build4.name,
|
||||
build5.name,
|
||||
build3.name,
|
||||
build1.name,
|
||||
]
|
||||
assert [b.name for b in db.search()] == [
|
||||
build1.name,
|
||||
build3.name,
|
||||
build5.name,
|
||||
build4.name,
|
||||
build2.name,
|
||||
]
|
||||
|
||||
|
||||
def test_count_by_status() -> None:
|
||||
db = BuildsDb()
|
||||
db.add(_make_build(name="b1", status=BuildStatus.started))
|
||||
|
|
|
|||
Loading…
Reference in a new issue