commit
480a7672ec
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -807,6 +807,7 @@ dependencies = [
|
|||||||
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pretty_env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pretty_env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"reqwest 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"reqwest 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -1211,6 +1212,11 @@ dependencies = [
|
|||||||
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "number_prefix"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl"
|
name = "openssl"
|
||||||
version = "0.10.20"
|
version = "0.10.20"
|
||||||
@ -2428,6 +2434,7 @@ dependencies = [
|
|||||||
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
|
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
|
||||||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||||
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
|
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
|
||||||
|
"checksum number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a"
|
||||||
"checksum openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)" = "5a0d6b781aac4ac1bd6cafe2a2f0ad8c16ae8e1dd5184822a16c50139f8838d9"
|
"checksum openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)" = "5a0d6b781aac4ac1bd6cafe2a2f0ad8c16ae8e1dd5184822a16c50139f8838d9"
|
||||||
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
|
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
|
||||||
"checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
|
"checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
|
||||||
|
@ -12,6 +12,7 @@ bytes = "0.4.12"
|
|||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
git2 = "0.8.0"
|
git2 = "0.8.0"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
|
number_prefix = "0.3.0"
|
||||||
openssl-probe = "0.1.2"
|
openssl-probe = "0.1.2"
|
||||||
pretty_env_logger = "0.3.0"
|
pretty_env_logger = "0.3.0"
|
||||||
reqwest = "0.9.15"
|
reqwest = "0.9.15"
|
||||||
|
34
src/main.rs
34
src/main.rs
@ -2,8 +2,6 @@
|
|||||||
extern crate actix_web;
|
extern crate actix_web;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
extern crate reqwest;
|
|
||||||
extern crate serde_json;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
@ -25,6 +23,7 @@ use badge::{Badge, BadgeOptions};
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::{unsync::mpsc, Stream};
|
use futures::{unsync::mpsc, Stream};
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
|
use number_prefix::{NumberPrefix, Prefixed, Standalone};
|
||||||
use std::{
|
use std::{
|
||||||
fs::create_dir_all,
|
fs::create_dir_all,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
@ -36,25 +35,32 @@ use structopt::StructOpt;
|
|||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
||||||
|
|
||||||
const COMMIT: &str = env!("VERGEN_SHA_SHORT");
|
pub struct VersionInfo<'a> {
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub commit: &'a str,
|
||||||
|
pub version: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
const VERSION_INFO: VersionInfo = VersionInfo {
|
||||||
|
commit: env!("VERGEN_SHA_SHORT"),
|
||||||
|
version: env!("CARGO_PKG_VERSION"),
|
||||||
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
static ref CLIENT: reqwest::Client = reqwest::Client::new();
|
||||||
static ref OPT: Opt = Opt::from_args();
|
static ref OPT: Opt = Opt::from_args();
|
||||||
static ref INDEX: Vec<u8> = {
|
static ref INDEX: Vec<u8> = {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
templates::index(&mut buf, COMMIT, VERSION, &OPT.domain).unwrap();
|
templates::index(&mut buf, VERSION_INFO, &OPT.domain).unwrap();
|
||||||
buf
|
buf
|
||||||
};
|
};
|
||||||
static ref P404: Vec<u8> = {
|
static ref P404: Vec<u8> = {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
templates::p404(&mut buf, COMMIT, VERSION).unwrap();
|
templates::p404(&mut buf, VERSION_INFO).unwrap();
|
||||||
buf
|
buf
|
||||||
};
|
};
|
||||||
static ref P500: Vec<u8> = {
|
static ref P500: Vec<u8> = {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
templates::p500(&mut buf, COMMIT, VERSION).unwrap();
|
templates::p500(&mut buf, VERSION_INFO).unwrap();
|
||||||
buf
|
buf
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -181,10 +187,14 @@ fn calculate_hoc<T: Service>(
|
|||||||
}
|
}
|
||||||
pull(&path)?;
|
pull(&path)?;
|
||||||
let (hoc, _) = hoc(&service_path, &state.repos, &state.cache)?;
|
let (hoc, _) = hoc(&service_path, &state.repos, &state.cache)?;
|
||||||
|
let hoc = match NumberPrefix::decimal(hoc as f64) {
|
||||||
|
Standalone(hoc) => hoc.to_string(),
|
||||||
|
Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
|
||||||
|
};
|
||||||
let badge_opt = BadgeOptions {
|
let badge_opt = BadgeOptions {
|
||||||
subject: "Hits-of-Code".to_string(),
|
subject: "Hits-of-Code".to_string(),
|
||||||
color: "#007ec6".to_string(),
|
color: "#007ec6".to_string(),
|
||||||
status: hoc.to_string(),
|
status: hoc,
|
||||||
};
|
};
|
||||||
let badge = Badge::new(badge_opt)?;
|
let badge = Badge::new(badge_opt)?;
|
||||||
|
|
||||||
@ -224,16 +234,20 @@ fn overview<T: Service>(
|
|||||||
}
|
}
|
||||||
pull(&path)?;
|
pull(&path)?;
|
||||||
let (hoc, head) = hoc(&service_path, &state.repos, &state.cache)?;
|
let (hoc, head) = hoc(&service_path, &state.repos, &state.cache)?;
|
||||||
|
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
|
||||||
|
Standalone(hoc) => hoc.to_string(),
|
||||||
|
Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
|
||||||
|
};
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let req_path = format!("{}/{}/{}", T::url_path(), data.0, data.1);
|
let req_path = format!("{}/{}/{}", T::url_path(), data.0, data.1);
|
||||||
templates::overview(
|
templates::overview(
|
||||||
&mut buf,
|
&mut buf,
|
||||||
COMMIT,
|
VERSION_INFO,
|
||||||
VERSION,
|
|
||||||
&OPT.domain,
|
&OPT.domain,
|
||||||
&req_path,
|
&req_path,
|
||||||
&url,
|
&url,
|
||||||
hoc,
|
hoc,
|
||||||
|
&hoc_pretty,
|
||||||
&head,
|
&head,
|
||||||
&T::commit_url(&repo, &head),
|
&T::commit_url(&repo, &head),
|
||||||
)?;
|
)?;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
@(title: &str, header: &str, content: Content, commit: &str, version: &str)
|
@use crate::VersionInfo;
|
||||||
|
|
||||||
|
@(title: &str, header: &str, content: Content, version_info: VersionInfo)
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@ -32,7 +34,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<small>HoC v@version - <a href="https://github.com/vbrandl/hoc/commit/@commit">@commit</a></small>
|
<small>HoC v@version_info.version - <a href="https://github.com/vbrandl/hoc/commit/@version_info.commit">@version_info.commit</a></small>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
|
@use crate::VersionInfo;
|
||||||
|
|
||||||
@(commit: &str, version: &str, domain: &str)
|
@(version_info: VersionInfo, domain: &str)
|
||||||
|
|
||||||
@:base("Hits-of-Code Badges", "Hits-of-Code Badges", {
|
@:base("Hits-of-Code Badges", "Hits-of-Code Badges", {
|
||||||
|
|
||||||
@ -60,4 +61,4 @@ my <a href="https://mirror.oldsql.cc/key.asc">GPG key</a>
|
|||||||
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
|
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
|
||||||
keyserver</a>), or by using any other UID from my key.
|
keyserver</a>), or by using any other UID from my key.
|
||||||
</p>
|
</p>
|
||||||
}, commit, version)
|
}, version_info)
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
|
@use crate::VersionInfo;
|
||||||
|
|
||||||
@(commit: &str, version: &str, domain: &str, path: &str, url: &str, hoc: u64, head: &str, commit_url: &str)
|
@(version_info: VersionInfo, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str)
|
||||||
|
|
||||||
@:base("Hits-of-Code Badges", "Overview", {
|
@:base("Hits-of-Code Badges", "Overview", {
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The project at <a href="@url">@url</a> has <strong>@hoc</strong> hits of code at <a href="@commit_url">@head</a>.
|
The project <a href="@url">@url</a> has <strong>@hoc_pretty</strong> (exactly @hoc) hits of code at <a href="@commit_url">@head</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -15,4 +16,4 @@ To include the badge in your readme, use the following markdown:
|
|||||||
<pre>
|
<pre>
|
||||||
[![Hits-of-Code](https://@domain/@path)](https://@domain/view/@path)
|
[![Hits-of-Code](https://@domain/@path)](https://@domain/view/@path)
|
||||||
</pre>
|
</pre>
|
||||||
}, commit, version)
|
}, version_info)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
|
@use crate::VersionInfo;
|
||||||
|
|
||||||
@(commit: &str, version: &str)
|
@(version_info: VersionInfo)
|
||||||
|
|
||||||
@:base("Page not Found - Hits-of-Code Badges", "404 - Page not Found", {
|
@:base("Page not Found - Hits-of-Code Badges", "404 - Page not Found", {
|
||||||
<p>
|
<p>
|
||||||
@ -10,4 +11,4 @@
|
|||||||
<p>
|
<p>
|
||||||
If you think, this is a mistake on my side, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
If you think, this is a mistake on my side, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
||||||
</p>
|
</p>
|
||||||
}, commit, version)
|
}, version_info)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
|
@use crate::VersionInfo;
|
||||||
|
|
||||||
@(commit: &str, version: &str)
|
@(version_info: VersionInfo)
|
||||||
|
|
||||||
@:base("Internal Server Error - Hits-of-Code Badges", "500 - Internal Server Error", {
|
@:base("Internal Server Error - Hits-of-Code Badges", "500 - Internal Server Error", {
|
||||||
<p>
|
<p>
|
||||||
@ -10,4 +11,4 @@
|
|||||||
<p>
|
<p>
|
||||||
If you think, this is a bug, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
If you think, this is a bug, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
||||||
</p>
|
</p>
|
||||||
}, commit, version)
|
}, version_info)
|
||||||
|
Loading…
Reference in New Issue
Block a user