Serve index document

Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
This commit is contained in:
Sergio Castaño Arteaga 2022-06-09 08:38:32 +02:00
parent 52a93c2c7a
commit d5cec39c3d
8 changed files with 44 additions and 38 deletions

51
Cargo.lock generated
View File

@ -51,45 +51,34 @@ checksum = "c5d78ce20460b82d3fa150275ed9d55e21064fc7951177baacf86a145c4a4b1f"
[[package]]
name = "askama"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139"
version = "0.11.2"
source = "git+https://github.com/djc/askama?rev=6cce13f076bdd3e8d9b0bf888c0464a1af9df25f#6cce13f076bdd3e8d9b0bf888c0464a1af9df25f"
dependencies = [
"askama_derive",
"askama_escape",
"askama_shared",
"humansize",
"num-traits",
"percent-encoding",
]
[[package]]
name = "askama_axum"
version = "0.1.0"
source = "git+https://github.com/djc/askama?rev=6cce13f076bdd3e8d9b0bf888c0464a1af9df25f#6cce13f076bdd3e8d9b0bf888c0464a1af9df25f"
dependencies = [
"askama",
"axum-core",
"http",
]
[[package]]
name = "askama_derive"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71"
version = "0.12.0"
source = "git+https://github.com/djc/askama?rev=6cce13f076bdd3e8d9b0bf888c0464a1af9df25f#6cce13f076bdd3e8d9b0bf888c0464a1af9df25f"
dependencies = [
"askama_shared",
"proc-macro2",
"syn",
]
[[package]]
name = "askama_escape"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]]
name = "askama_shared"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0"
dependencies = [
"askama_escape",
"humansize",
"mime",
"mime_guess",
"nom",
"num-traits",
"percent-encoding",
"proc-macro2",
"quote",
"serde",
@ -97,6 +86,11 @@ dependencies = [
"toml",
]
[[package]]
name = "askama_escape"
version = "0.10.3"
source = "git+https://github.com/djc/askama?rev=6cce13f076bdd3e8d9b0bf888c0464a1af9df25f#6cce13f076bdd3e8d9b0bf888c0464a1af9df25f"
[[package]]
name = "async-trait"
version = "0.1.53"
@ -630,6 +624,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"askama",
"askama_axum",
"axum",
"clap",
"config",

View File

@ -5,7 +5,8 @@ edition = "2021"
[dependencies]
anyhow = "1.0.57"
askama = "0.11.1"
askama = { git = "https://github.com/djc/askama", rev = "6cce13f076bdd3e8d9b0bf888c0464a1af9df25f" }
askama_axum = { git = "https://github.com/djc/askama", rev = "6cce13f076bdd3e8d9b0bf888c0464a1af9df25f" }
axum = "0.5.6"
clap = { version = "3.1.18", features = ["derive"] }
config = "0.13.1"

View File

@ -72,9 +72,3 @@ pub(crate) struct Issue {
pub(crate) struct Repository {
pub full_name: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub(crate) struct Reaction {
pub user: User,
pub content: String,
}

View File

@ -1,5 +1,6 @@
use crate::{
events::{Event, EventError, IssueCommentEvent},
templates,
votes::Command,
};
use anyhow::{format_err, Error, Result};
@ -51,7 +52,7 @@ pub(crate) async fn setup_router(cmds_tx: Sender<Command>) -> Result<Router> {
/// Handler that returns the index document.
async fn index() -> impl IntoResponse {
"Welcome to GitVote!"
templates::Index {}
}
/// Handler that processes webhook events from GitHub.

View File

@ -74,6 +74,8 @@ async fn main() -> Result<()> {
Ok(())
}
/// Return a future that will complete when the program is asked to stop via a
/// ctrl+c or terminate signal.
async fn shutdown_signal() {
// Setup signal handlers
let ctrl_c = async {

View File

@ -5,6 +5,11 @@ use crate::{
};
use askama::Template;
/// Template for the index document.
#[derive(Debug, Clone, Template)]
#[template(path = "index.html")]
pub(crate) struct Index {}
/// Template for the vote created comment.
#[derive(Debug, Clone, Template)]
#[template(path = "vote-created.md")]

View File

@ -1,5 +1,5 @@
use crate::{
events::{IssueCommentEvent, IssueCommentEventAction, Reaction},
events::{IssueCommentEvent, IssueCommentEventAction, User},
metadata::Metadata,
templates,
};
@ -75,6 +75,14 @@ pub(crate) struct VoteResults {
pub voters: HashMap<String, String>,
}
/// Represents a reaction on an issue or pull request comment, which is the way
/// of casting a vote.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub(crate) struct Reaction {
pub user: User,
pub content: String,
}
/// A votes processor is in charge of creating the votes requested, stopping
/// them at the scheduled time and publishing results, etc.
pub(crate) struct Processor {

View File

@ -135,7 +135,7 @@
a vote on issues and pull requests
</div>
<a class="link" href="https://github.com/tegioz/gitvote" target="_blank">
<a class="link" href="https://github.com/cncf/gitvote" target="_blank">
<div class="linkContent">
<div class="githubIcon">
<svg viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">