Remove /commit/ endpoint
This commit is contained in:
parent
c713abc5d3
commit
d5a41abaff
5 changed files with 139 additions and 166 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
mod api;
|
mod api;
|
||||||
mod commit;
|
mod commit;
|
||||||
mod commit_hash;
|
|
||||||
mod index;
|
mod index;
|
||||||
mod queue;
|
mod queue;
|
||||||
mod r#static;
|
mod r#static;
|
||||||
|
|
@ -44,8 +43,7 @@ pub async fn run(server: Server) -> 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/:hash", get(commit::get))
|
||||||
.route("/commit/:hash", get(commit_hash::get))
|
|
||||||
.route("/queue/", get(queue::get))
|
.route("/queue/", get(queue::get))
|
||||||
.route("/queue/table", get(queue::get_table))
|
.route("/queue/table", get(queue::get_table))
|
||||||
.merge(api::router(&server))
|
.merge(api::router(&server))
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,114 @@
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::{extract::State, response::IntoResponse};
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use crate::{config::Config, somehow};
|
use crate::{config::Config, server::util, somehow};
|
||||||
|
|
||||||
use super::{Base, Tab};
|
use super::{Base, Tab};
|
||||||
|
|
||||||
|
struct Commit {
|
||||||
|
hash: String,
|
||||||
|
short: String,
|
||||||
|
reachable: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Commit {
|
||||||
|
fn new(hash: String, message: &str, reachable: i64) -> Self {
|
||||||
|
Self {
|
||||||
|
short: util::format_commit_short(&hash, message),
|
||||||
|
hash,
|
||||||
|
reachable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "commit.html")]
|
#[template(path = "commit.html")]
|
||||||
struct CommitTemplate {
|
struct CommitTemplate {
|
||||||
base: Base,
|
base: Base,
|
||||||
|
hash: String,
|
||||||
|
author: String,
|
||||||
|
author_date: String,
|
||||||
|
commit: String,
|
||||||
|
commit_date: String,
|
||||||
|
parents: Vec<Commit>,
|
||||||
|
children: Vec<Commit>,
|
||||||
|
summary: String,
|
||||||
|
message: String,
|
||||||
|
reachable: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(State(config): State<&'static Config>) -> somehow::Result<impl IntoResponse> {
|
pub async fn get(
|
||||||
|
Path(hash): Path<String>,
|
||||||
|
State(config): State<&'static Config>,
|
||||||
|
State(db): State<SqlitePool>,
|
||||||
|
) -> somehow::Result<Response> {
|
||||||
|
let Some(commit) = sqlx::query!(
|
||||||
|
"\
|
||||||
|
SELECT \
|
||||||
|
hash, \
|
||||||
|
author, \
|
||||||
|
author_date AS \"author_date: time::OffsetDateTime\", \
|
||||||
|
committer, \
|
||||||
|
committer_date AS \"committer_date: time::OffsetDateTime\", \
|
||||||
|
message, \
|
||||||
|
reachable \
|
||||||
|
FROM commits \
|
||||||
|
WHERE hash = ? \
|
||||||
|
",
|
||||||
|
hash
|
||||||
|
)
|
||||||
|
.fetch_optional(&db)
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
return Ok(StatusCode::NOT_FOUND.into_response());
|
||||||
|
};
|
||||||
|
|
||||||
|
let parents = sqlx::query!(
|
||||||
|
"\
|
||||||
|
SELECT hash, message, reachable FROM commits \
|
||||||
|
JOIN commit_links ON hash = parent \
|
||||||
|
WHERE child = ? \
|
||||||
|
ORDER BY reachable DESC, unixepoch(committer_date) ASC \
|
||||||
|
",
|
||||||
|
hash
|
||||||
|
)
|
||||||
|
.fetch(&db)
|
||||||
|
.map_ok(|r| Commit::new(r.hash, &r.message, r.reachable))
|
||||||
|
.try_collect::<Vec<_>>()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let children = sqlx::query!(
|
||||||
|
"\
|
||||||
|
SELECT hash, message, reachable FROM commits \
|
||||||
|
JOIN commit_links ON hash = child \
|
||||||
|
WHERE parent = ? \
|
||||||
|
ORDER BY reachable DESC, unixepoch(committer_date) ASC \
|
||||||
|
",
|
||||||
|
hash
|
||||||
|
)
|
||||||
|
.fetch(&db)
|
||||||
|
.map_ok(|r| Commit::new(r.hash, &r.message, r.reachable))
|
||||||
|
.try_collect::<Vec<_>>()
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(CommitTemplate {
|
Ok(CommitTemplate {
|
||||||
base: Base::new(config, Tab::Commit),
|
base: Base::new(config, Tab::Commit),
|
||||||
})
|
hash: commit.hash,
|
||||||
|
author: commit.author,
|
||||||
|
author_date: util::format_time(commit.author_date),
|
||||||
|
commit: commit.committer,
|
||||||
|
commit_date: util::format_time(commit.committer_date),
|
||||||
|
parents,
|
||||||
|
children,
|
||||||
|
summary: util::format_commit_summary(&commit.message),
|
||||||
|
message: commit.message.trim_end().to_string(),
|
||||||
|
reachable: commit.reachable,
|
||||||
|
}
|
||||||
|
.into_response())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,114 +0,0 @@
|
||||||
use askama::Template;
|
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use futures::TryStreamExt;
|
|
||||||
use sqlx::SqlitePool;
|
|
||||||
|
|
||||||
use crate::{config::Config, server::util, somehow};
|
|
||||||
|
|
||||||
use super::{Base, Tab};
|
|
||||||
|
|
||||||
struct Commit {
|
|
||||||
hash: String,
|
|
||||||
short: String,
|
|
||||||
reachable: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Commit {
|
|
||||||
fn new(hash: String, message: &str, reachable: i64) -> Self {
|
|
||||||
Self {
|
|
||||||
short: util::format_commit_short(&hash, message),
|
|
||||||
hash,
|
|
||||||
reachable,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(path = "commit_hash.html")]
|
|
||||||
struct CommitHashTemplate {
|
|
||||||
base: Base,
|
|
||||||
hash: String,
|
|
||||||
author: String,
|
|
||||||
author_date: String,
|
|
||||||
commit: String,
|
|
||||||
commit_date: String,
|
|
||||||
parents: Vec<Commit>,
|
|
||||||
children: Vec<Commit>,
|
|
||||||
summary: String,
|
|
||||||
message: String,
|
|
||||||
reachable: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get(
|
|
||||||
Path(hash): Path<String>,
|
|
||||||
State(config): State<&'static Config>,
|
|
||||||
State(db): State<SqlitePool>,
|
|
||||||
) -> somehow::Result<Response> {
|
|
||||||
let Some(commit) = sqlx::query!(
|
|
||||||
"\
|
|
||||||
SELECT \
|
|
||||||
hash, \
|
|
||||||
author, \
|
|
||||||
author_date AS \"author_date: time::OffsetDateTime\", \
|
|
||||||
committer, \
|
|
||||||
committer_date AS \"committer_date: time::OffsetDateTime\", \
|
|
||||||
message, \
|
|
||||||
reachable \
|
|
||||||
FROM commits \
|
|
||||||
WHERE hash = ? \
|
|
||||||
",
|
|
||||||
hash
|
|
||||||
)
|
|
||||||
.fetch_optional(&db)
|
|
||||||
.await?
|
|
||||||
else {
|
|
||||||
return Ok(StatusCode::NOT_FOUND.into_response());
|
|
||||||
};
|
|
||||||
|
|
||||||
let parents = sqlx::query!(
|
|
||||||
"\
|
|
||||||
SELECT hash, message, reachable FROM commits \
|
|
||||||
JOIN commit_links ON hash = parent \
|
|
||||||
WHERE child = ? \
|
|
||||||
ORDER BY reachable DESC, unixepoch(committer_date) ASC \
|
|
||||||
",
|
|
||||||
hash
|
|
||||||
)
|
|
||||||
.fetch(&db)
|
|
||||||
.map_ok(|r| Commit::new(r.hash, &r.message, r.reachable))
|
|
||||||
.try_collect::<Vec<_>>()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let children = sqlx::query!(
|
|
||||||
"\
|
|
||||||
SELECT hash, message, reachable FROM commits \
|
|
||||||
JOIN commit_links ON hash = child \
|
|
||||||
WHERE parent = ? \
|
|
||||||
ORDER BY reachable DESC, unixepoch(committer_date) ASC \
|
|
||||||
",
|
|
||||||
hash
|
|
||||||
)
|
|
||||||
.fetch(&db)
|
|
||||||
.map_ok(|r| Commit::new(r.hash, &r.message, r.reachable))
|
|
||||||
.try_collect::<Vec<_>>()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(CommitHashTemplate {
|
|
||||||
base: Base::new(config, Tab::Commit),
|
|
||||||
hash: commit.hash,
|
|
||||||
author: commit.author,
|
|
||||||
author_date: util::format_time(commit.author_date),
|
|
||||||
commit: commit.committer,
|
|
||||||
commit_date: util::format_time(commit.committer_date),
|
|
||||||
parents,
|
|
||||||
children,
|
|
||||||
summary: util::format_commit_summary(&commit.message),
|
|
||||||
message: commit.message.trim_end().to_string(),
|
|
||||||
reachable: commit.reachable,
|
|
||||||
}
|
|
||||||
.into_response())
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,43 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% import "util.html" as util %}
|
||||||
|
|
||||||
{% block title %}commit{% endblock %}
|
{% block title %}{{ summary }}{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
Sorry, nothing here yet.
|
<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 }}">
|
||||||
|
{% call util::commit_short(commit.short, commit.reachable)%}
|
||||||
|
</a>
|
||||||
|
</dd>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for commit in children %}
|
||||||
|
<dt>Child:</dt>
|
||||||
|
<dd>
|
||||||
|
<a href="{{ commit.hash }}">
|
||||||
|
{% call util::commit_short(commit.short, commit.reachable)%}
|
||||||
|
</a>
|
||||||
|
</dd>
|
||||||
|
{% endfor %}
|
||||||
|
</dl>
|
||||||
|
<pre class="{% call util::r_class(reachable) %}" title="{% call util::r_title(reachable) %}">{{ message }}</pre>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
{% extends "base.html" %}
|
|
||||||
{% import "util.html" as util %}
|
|
||||||
|
|
||||||
{% 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 }}">
|
|
||||||
{% call util::commit_short(commit.short, commit.reachable)%}
|
|
||||||
</a>
|
|
||||||
</dd>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% for commit in children %}
|
|
||||||
<dt>Child:</dt>
|
|
||||||
<dd>
|
|
||||||
<a href="{{ commit.hash }}">
|
|
||||||
{% call util::commit_short(commit.short, commit.reachable)%}
|
|
||||||
</a>
|
|
||||||
</dd>
|
|
||||||
{% endfor %}
|
|
||||||
</dl>
|
|
||||||
<pre class="{% call util::r_class(reachable) %}" title="{% call util::r_title(reachable) %}">{{ message }}</pre>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue