List tracked refs on index page
This commit is contained in:
parent
2b4a5d4021
commit
3b4d8dab72
5 changed files with 89 additions and 8 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
mod config;
|
mod config;
|
||||||
mod recurring;
|
mod recurring;
|
||||||
|
mod repo;
|
||||||
mod somehow;
|
mod somehow;
|
||||||
mod state;
|
mod state;
|
||||||
mod web;
|
mod web;
|
||||||
|
|
|
||||||
14
src/repo.rs
Normal file
14
src/repo.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
//! Utility functions for accessing a [`Repository`].
|
||||||
|
|
||||||
|
use gix::{ObjectId, Repository};
|
||||||
|
|
||||||
|
use crate::somehow;
|
||||||
|
|
||||||
|
pub fn short_commit(repo: &Repository, hash: &str) -> somehow::Result<String> {
|
||||||
|
let hash = hash.parse::<ObjectId>()?;
|
||||||
|
let commit = repo.find_object(hash)?.try_into_commit()?;
|
||||||
|
|
||||||
|
let id = commit.short_id()?;
|
||||||
|
let summary = commit.message()?.summary();
|
||||||
|
Ok(format!("{id} ({summary})"))
|
||||||
|
}
|
||||||
|
|
@ -1,18 +1,48 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::{extract::State, response::IntoResponse};
|
use axum::{extract::State, response::IntoResponse};
|
||||||
|
use gix::ThreadSafeRepository;
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::{config::Config, repo, somehow};
|
||||||
|
|
||||||
|
struct Ref {
|
||||||
|
name: String,
|
||||||
|
hash: String,
|
||||||
|
short: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "index.html")]
|
#[template(path = "index.html")]
|
||||||
struct IndexTemplate {
|
struct IndexTemplate {
|
||||||
base: String,
|
base: String,
|
||||||
repo_name: String,
|
repo_name: String,
|
||||||
|
refs: Vec<Ref>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(State(config): State<&'static Config>) -> super::Result<impl IntoResponse> {
|
pub async fn get(
|
||||||
|
State(config): State<&'static Config>,
|
||||||
|
State(db): State<SqlitePool>,
|
||||||
|
State(repo): State<Arc<ThreadSafeRepository>>,
|
||||||
|
) -> somehow::Result<impl IntoResponse> {
|
||||||
|
let repo = repo.to_thread_local();
|
||||||
|
|
||||||
|
let rows = sqlx::query!("SELECT name, hash FROM tracked_refs")
|
||||||
|
.fetch_all(&db)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut refs = vec![];
|
||||||
|
for row in rows {
|
||||||
|
let name = row.name;
|
||||||
|
let hash = row.hash;
|
||||||
|
let short = repo::short_commit(&repo, &hash)?;
|
||||||
|
refs.push(Ref { name, hash, short });
|
||||||
|
}
|
||||||
|
|
||||||
Ok(IndexTemplate {
|
Ok(IndexTemplate {
|
||||||
base: config.web.base(),
|
base: config.web.base(),
|
||||||
repo_name: config.repo.name(),
|
repo_name: config.repo.name(),
|
||||||
|
refs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,12 @@
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Nav bar */
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
line-height: 1.2em;
|
line-height: 1.2em;
|
||||||
|
margin-bottom: 1.5em;
|
||||||
padding: 0.3em;
|
padding: 0.3em;
|
||||||
background-color: #bdf;
|
background-color: #bdf;
|
||||||
border-radius: 0.3em;
|
border-radius: 0.3em;
|
||||||
|
|
@ -33,11 +36,6 @@ nav> :last-child {
|
||||||
|
|
||||||
nav a {
|
nav a {
|
||||||
color: black;
|
color: black;
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nav img {
|
nav img {
|
||||||
|
|
@ -45,3 +43,25 @@ nav img {
|
||||||
height: 1.2em;
|
height: 1.2em;
|
||||||
vertical-align: -20%;
|
vertical-align: -20%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* General */
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 0 1ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
tbody tr:nth-child(odd) {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,21 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>{{ repo_name }}</h1>
|
<h2>Tracked refs</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ref</th>
|
||||||
|
<th>points to</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for ref in refs %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ ref.name }}</td>
|
||||||
|
<td><a href="{{ base }}/commit/{{ ref.hash }}">{{ ref.short }}</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue