Add /commit/:hash page
This commit is contained in:
parent
965efa5b58
commit
128384bcf7
5 changed files with 169 additions and 0 deletions
20
.sqlx/query-c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719.json
generated
Normal file
20
.sqlx/query-c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719.json
generated
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "SELECT child FROM commit_links WHERE parent = ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "child",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719"
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
mod commit;
|
mod commit;
|
||||||
|
mod commit_hash;
|
||||||
mod index;
|
mod index;
|
||||||
mod r#static;
|
mod r#static;
|
||||||
|
|
||||||
|
|
@ -12,6 +13,7 @@ pub async fn run(state: AppState) -> somehow::Result<()> {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(index::get))
|
.route("/", get(index::get))
|
||||||
.route("/commit/", get(commit::get))
|
.route("/commit/", get(commit::get))
|
||||||
|
.route("/commit/:hash", get(commit_hash::get))
|
||||||
.fallback(get(r#static::static_handler))
|
.fallback(get(r#static::static_handler))
|
||||||
.with_state(state.clone());
|
.with_state(state.clone());
|
||||||
|
|
||||||
|
|
|
||||||
90
src/web/commit_hash.rs
Normal file
90
src/web/commit_hash.rs
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use askama::Template;
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
response::IntoResponse,
|
||||||
|
};
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
use gix::{prelude::ObjectIdExt, Id, ObjectId, ThreadSafeRepository};
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
|
use crate::{config::Config, repo, somehow};
|
||||||
|
|
||||||
|
struct Commit {
|
||||||
|
hash: String,
|
||||||
|
description: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Commit {
|
||||||
|
fn new(id: Id<'_>) -> somehow::Result<Self> {
|
||||||
|
let commit = id.object()?.try_into_commit()?;
|
||||||
|
Ok(Self {
|
||||||
|
hash: id.to_string(),
|
||||||
|
description: repo::format_commit_short(&commit)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "commit_hash.html")]
|
||||||
|
struct CommitIdTemplate {
|
||||||
|
base: String,
|
||||||
|
repo_name: String,
|
||||||
|
current: String,
|
||||||
|
hash: String,
|
||||||
|
summary: String,
|
||||||
|
message: String,
|
||||||
|
author: String,
|
||||||
|
author_date: String,
|
||||||
|
commit: String,
|
||||||
|
commit_date: String,
|
||||||
|
parents: Vec<Commit>,
|
||||||
|
children: Vec<Commit>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get(
|
||||||
|
Path(hash): Path<String>,
|
||||||
|
State(config): State<&'static Config>,
|
||||||
|
State(db): State<SqlitePool>,
|
||||||
|
State(repo): State<Arc<ThreadSafeRepository>>,
|
||||||
|
) -> somehow::Result<impl IntoResponse> {
|
||||||
|
// Do this first because a &Repository can't be kept across awaits.
|
||||||
|
let child_ids = sqlx::query!("SELECT child FROM commit_links WHERE parent = ?", hash)
|
||||||
|
.fetch(&db)
|
||||||
|
.map_ok(|r| r.child)
|
||||||
|
.try_collect::<Vec<_>>()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let repo = repo.to_thread_local();
|
||||||
|
let id = hash.parse::<ObjectId>()?.attach(&repo);
|
||||||
|
let commit = id.object()?.try_into_commit()?;
|
||||||
|
let author_info = commit.author()?;
|
||||||
|
let committer_info = commit.committer()?;
|
||||||
|
|
||||||
|
let mut parents = vec![];
|
||||||
|
for id in commit.parent_ids() {
|
||||||
|
parents.push(Commit::new(id)?);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut children = vec![];
|
||||||
|
for hash in child_ids {
|
||||||
|
let id = hash.parse::<ObjectId>()?.attach(&repo);
|
||||||
|
children.push(Commit::new(id)?);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(CommitIdTemplate {
|
||||||
|
base: config.web.base(),
|
||||||
|
repo_name: config.repo.name(),
|
||||||
|
current: "commit".to_string(),
|
||||||
|
hash: id.to_string(),
|
||||||
|
summary: commit.message()?.summary().to_string(),
|
||||||
|
message: commit.message_raw_sloppy().to_string(),
|
||||||
|
author: repo::format_actor(author_info.actor())?,
|
||||||
|
author_date: author_info.time.to_bstring().to_string(),
|
||||||
|
commit: repo::format_actor(committer_info.actor())?,
|
||||||
|
commit_date: committer_info.time.to_bstring().to_string(),
|
||||||
|
parents,
|
||||||
|
children,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
:root {
|
:root {
|
||||||
|
--lh: 1.3em;
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
|
line-height: var(--lh);
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,3 +61,24 @@ a:hover {
|
||||||
dd {
|
dd {
|
||||||
margin-left: 4ch;
|
margin-left: 4ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Commit */
|
||||||
|
|
||||||
|
.commit * {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.commit .hash {
|
||||||
|
color: #b70;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.commit .message {
|
||||||
|
margin: 1em 0ch 1em 4ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.commit dl {
|
||||||
|
display: grid;
|
||||||
|
grid: auto-flow / min-content max-content;
|
||||||
|
column-gap: 1ch;
|
||||||
|
}
|
||||||
|
|
|
||||||
34
templates/commit_hash.html
Normal file
34
templates/commit_hash.html
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ summary }}{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h2>Commit</h2>
|
||||||
|
<div class="commit">
|
||||||
|
<span class="hash">commit {{ hash }}</span>
|
||||||
|
<dl>
|
||||||
|
<dt>Author:</dt>
|
||||||
|
<dd>{{ author }}</dd>
|
||||||
|
|
||||||
|
<dt>AuthorDate:</dt>
|
||||||
|
<dd>{{ author_date }}</dd>
|
||||||
|
|
||||||
|
<dt>Commit:</dt>
|
||||||
|
<dd>{{ commit }}</dd>
|
||||||
|
|
||||||
|
<dt>CommitDate:</dt>
|
||||||
|
<dd>{{ commit_date }}</dd>
|
||||||
|
|
||||||
|
{% for commit in parents %}
|
||||||
|
<dt>Parent:</dt>
|
||||||
|
<dd><a href="{{ commit.hash }}">{{ commit.description }}</a></dd>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for commit in children %}
|
||||||
|
<dt>Child:</dt>
|
||||||
|
<dd><a href="{{ commit.hash }}">{{ commit.description }}</a></dd>
|
||||||
|
{% endfor %}
|
||||||
|
</dl>
|
||||||
|
<pre class="message">{{ message }}</pre>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue