Skip to content

Commit

Permalink
feat: add info about merged prs to dashboard, replace icons
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Feb 15, 2024
1 parent 24b6eca commit 902df7e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
46 changes: 28 additions & 18 deletions otterdog/webapp/db/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
4 changes: 3 additions & 1 deletion otterdog/webapp/home/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down
16 changes: 15 additions & 1 deletion otterdog/webapp/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h3>{{ installations|length }}</h3>
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>{{ pull_request_count }}</h3>
<h3>{{ open_pull_request_count }}</h3>
<p>Open Pull Requests</p>
</div>
<div class="icon">
Expand All @@ -74,6 +74,20 @@ <h3>{{ pull_request_count }}</h3>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-6">
<!-- small box -->
<div class="small-box bg-success">
<div class="inner">
<h3>{{ merged_pull_request_count }}</h3>
<p>Merged Pull Requests</p>
</div>
<div class="icon">
<i class="fas fa-code-pull-request"></i>
</div>
<a href="/admin/pullrequests" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
</div>
<!-- ./row -->

Expand Down
6 changes: 3 additions & 3 deletions otterdog/webapp/templates/includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="/" class="brand-link">
<img src="/static/assets/img/AdminLTELogo.png" alt="AdminLTE Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
<i class="fas fa-otter"></i>
<span class="brand-text font-weight-light">Otterdog</span>
</a>

Expand Down Expand Up @@ -48,7 +48,7 @@
{% for nav_level2, value_level2 in value_level1|dictsort %}
<li class="nav-item">
<a href="/projects/{{ value_level2.project_name }}" class="nav-link {% if nav_level2 in segments[1] %} active {% endif %}">
<i class="nav-icon fas fa-code-pull-request"></i>
<i class="nav-icon fab fa-square-github"></i>
<p>
{{ value_level2.project_name }}
<i class="fas nav-icon"></i>
Expand All @@ -61,7 +61,7 @@
{% else %}
<li class="nav-item">
<a href="/projects/{{ value_level1.project_name }}" class="nav-link {% if value_level1.project_name in segments %} active {% endif %}">
<i class="nav-icon fas fa-code-pull-request"></i>
<i class="nav-icon fab fa-square-github"></i>
<p>
{{ value_level1.project_name }}
<i class="fas nav-icon"></i>
Expand Down

0 comments on commit 902df7e

Please sign in to comment.