diff --git a/otterdog/webapp/db/service.py b/otterdog/webapp/db/service.py index 35046b77..86e88eee 100644 --- a/otterdog/webapp/db/service.py +++ b/otterdog/webapp/db/service.py @@ -11,6 +11,7 @@ from logging import getLogger from odmantic import query +from odmantic.query import QueryExpression from quart import current_app from otterdog.webapp import mongo @@ -284,36 +285,45 @@ async def update_pull_request(pull_request: PullRequestModel) -> None: async def get_open_or_incomplete_pull_requests() -> list[PullRequestModel]: return await mongo.odm.find( PullRequestModel, - query.or_( - PullRequestModel.status == PullRequestStatus.OPEN, - query.and_( - PullRequestModel.status == PullRequestStatus.MERGED, - PullRequestModel.apply_status != ApplyStatus.COMPLETED, - ), - ), + _open_or_incomplete_pull_requests_query(), ) async def get_open_or_incomplete_pull_requests_count() -> int: return await mongo.odm.count( PullRequestModel, - query.or_( - PullRequestModel.status == PullRequestStatus.OPEN, - query.and_( - PullRequestModel.status == PullRequestStatus.MERGED, - PullRequestModel.apply_status != ApplyStatus.COMPLETED, - ), - ), + _open_or_incomplete_pull_requests_query(), ) -async def get_merged_pull_requests(limit: int) -> list[PullRequestModel]: - return await mongo.odm.find( - PullRequestModel, +def _open_or_incomplete_pull_requests_query() -> QueryExpression: + return query.or_( + PullRequestModel.status == PullRequestStatus.OPEN, query.and_( PullRequestModel.status == PullRequestStatus.MERGED, - PullRequestModel.apply_status == ApplyStatus.COMPLETED, + PullRequestModel.apply_status != ApplyStatus.COMPLETED, ), + ) + + +async def get_merged_pull_requests(limit: int | None = None) -> list[PullRequestModel]: + return await mongo.odm.find( + PullRequestModel, + _merged_pull_requests_query(), limit=limit, sort=query.desc(PullRequestModel.merged_at), ) + + +async def get_merged_pull_requests_count() -> int: + return await mongo.odm.count( + PullRequestModel, + _merged_pull_requests_query(), + ) + + +def _merged_pull_requests_query() -> QueryExpression: + return query.and_( + PullRequestModel.status == PullRequestStatus.MERGED, + PullRequestModel.apply_status == ApplyStatus.COMPLETED, + ) diff --git a/otterdog/webapp/home/routes.py b/otterdog/webapp/home/routes.py index 3316ecbe..f798990b 100644 --- a/otterdog/webapp/home/routes.py +++ b/otterdog/webapp/home/routes.py @@ -19,6 +19,7 @@ get_configurations, get_installations, get_merged_pull_requests, + get_merged_pull_requests_count, get_open_or_incomplete_pull_requests, get_open_or_incomplete_pull_requests_count, get_tasks, @@ -41,7 +42,8 @@ async def index(): configurations_by_key = associate_by_key(configurations, lambda x: x.github_id) return await render_home_template( "index.html", - pull_request_count=await get_open_or_incomplete_pull_requests_count(), + open_pull_request_count=await get_open_or_incomplete_pull_requests_count(), + merged_pull_request_count=await get_merged_pull_requests_count(), installations=installations, configurations=configurations_by_key, ) diff --git a/otterdog/webapp/templates/home/index.html b/otterdog/webapp/templates/home/index.html index 41cdf000..284437e0 100644 --- a/otterdog/webapp/templates/home/index.html +++ b/otterdog/webapp/templates/home/index.html @@ -64,7 +64,7 @@
Open Pull Requests