From f6cbe92ebaf1c1d257e4dd102623fba18dabfe24 Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Tue, 30 Apr 2019 14:18:30 +0200
Subject: [PATCH 1/5] Add number-prefix crate
---
Cargo.lock | 7 +++++++
Cargo.toml | 1 +
2 files changed, 8 insertions(+)
diff --git a/Cargo.lock b/Cargo.lock
index 595c12b..e69d97a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -807,6 +807,7 @@ dependencies = [
"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)",
"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)",
"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)",
@@ -1211,6 +1212,11 @@ dependencies = [
"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]]
name = "openssl"
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.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 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-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"
diff --git a/Cargo.toml b/Cargo.toml
index a8c47ce..04169e7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ bytes = "0.4.12"
futures = "0.1.25"
git2 = "0.8.0"
lazy_static = "1.3.0"
+number_prefix = "0.3.0"
openssl-probe = "0.1.2"
pretty_env_logger = "0.3.0"
reqwest = "0.9.15"
From bdf9d382d43691a959c2b358ced6a9a53e42381e Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Tue, 30 Apr 2019 14:19:40 +0200
Subject: [PATCH 2/5] Use version info struct
---
src/main.rs | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index cd138ed..95d67de 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -36,25 +36,32 @@ use structopt::StructOpt;
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
-const COMMIT: &str = env!("VERGEN_SHA_SHORT");
-const VERSION: &str = env!("CARGO_PKG_VERSION");
+pub struct VersionInfo<'a> {
+ 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! {
static ref CLIENT: reqwest::Client = reqwest::Client::new();
static ref OPT: Opt = Opt::from_args();
static ref INDEX: Vec = {
let mut buf = Vec::new();
- templates::index(&mut buf, COMMIT, VERSION, &OPT.domain).unwrap();
+ templates::index(&mut buf, VERSION_INFO, &OPT.domain).unwrap();
buf
};
static ref P404: Vec = {
let mut buf = Vec::new();
- templates::p404(&mut buf, COMMIT, VERSION).unwrap();
+ templates::p404(&mut buf, VERSION_INFO).unwrap();
buf
};
static ref P500: Vec = {
let mut buf = Vec::new();
- templates::p500(&mut buf, COMMIT, VERSION).unwrap();
+ templates::p500(&mut buf, VERSION_INFO).unwrap();
buf
};
}
@@ -228,8 +235,7 @@ fn overview(
let req_path = format!("{}/{}/{}", T::url_path(), data.0, data.1);
templates::overview(
&mut buf,
- COMMIT,
- VERSION,
+ VERSION_INFO,
&OPT.domain,
&req_path,
&url,
From 1f807a14fbe78fcd8b02bb0403b52b48bc4df70a Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Tue, 30 Apr 2019 14:20:11 +0200
Subject: [PATCH 3/5] Use version info struct
---
templates/base.rs.html | 6 ++++--
templates/index.rs.html | 5 +++--
templates/overview.rs.html | 7 ++++---
templates/p404.rs.html | 5 +++--
templates/p500.rs.html | 5 +++--
5 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/templates/base.rs.html b/templates/base.rs.html
index 115b14b..567cc7e 100644
--- a/templates/base.rs.html
+++ b/templates/base.rs.html
@@ -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)
@@ -32,7 +34,7 @@
diff --git a/templates/index.rs.html b/templates/index.rs.html
index da129fe..ec004cc 100644
--- a/templates/index.rs.html
+++ b/templates/index.rs.html
@@ -1,6 +1,7 @@
@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", {
@@ -60,4 +61,4 @@ my GPG key
(from a
keyserver), or by using any other UID from my key.
-}, commit, version)
+}, version_info)
diff --git a/templates/overview.rs.html b/templates/overview.rs.html
index c01ff0a..a9cdd3c 100644
--- a/templates/overview.rs.html
+++ b/templates/overview.rs.html
@@ -1,11 +1,12 @@
@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", {
-The project at @url has @hoc hits of code at @head.
+The project @url has @hoc_pretty (exactly @hoc) hits of code at @head.
@@ -15,4 +16,4 @@ To include the badge in your readme, use the following markdown:
[![Hits-of-Code](https://@domain/@path)](https://@domain/view/@path)
-}, commit, version)
+}, version_info)
diff --git a/templates/p404.rs.html b/templates/p404.rs.html
index 1ae929a..8189f6f 100644
--- a/templates/p404.rs.html
+++ b/templates/p404.rs.html
@@ -1,6 +1,7 @@
@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", {
@@ -10,4 +11,4 @@
If you think, this is a mistake on my side, please drop me a mail.
-}, commit, version)
+}, version_info)
diff --git a/templates/p500.rs.html b/templates/p500.rs.html
index 0bdebeb..4798fca 100644
--- a/templates/p500.rs.html
+++ b/templates/p500.rs.html
@@ -1,6 +1,7 @@
@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", {
@@ -10,4 +11,4 @@
If you think, this is a bug, please drop me a mail.
-}, commit, version)
+}, version_info)
From 6b68d291c8a33d3d07bd025c00b7731a9b7b0de0 Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Tue, 30 Apr 2019 14:20:33 +0200
Subject: [PATCH 4/5] Use prefixed numbers for badges
---
src/main.rs | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/main.rs b/src/main.rs
index 95d67de..c8bd1ef 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,6 +25,7 @@ use badge::{Badge, BadgeOptions};
use bytes::Bytes;
use futures::{unsync::mpsc, Stream};
use git2::Repository;
+use number_prefix::{NumberPrefix, Prefixed, Standalone};
use std::{
fs::create_dir_all,
path::{Path, PathBuf},
@@ -188,10 +189,14 @@ fn calculate_hoc(
}
pull(&path)?;
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 {
subject: "Hits-of-Code".to_string(),
color: "#007ec6".to_string(),
- status: hoc.to_string(),
+ status: hoc,
};
let badge = Badge::new(badge_opt)?;
@@ -231,6 +236,10 @@ fn overview(
}
pull(&path)?;
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 req_path = format!("{}/{}/{}", T::url_path(), data.0, data.1);
templates::overview(
@@ -240,6 +249,7 @@ fn overview(
&req_path,
&url,
hoc,
+ &hoc_pretty,
&head,
&T::commit_url(&repo, &head),
)?;
From a0ea761dd83a2547d95aa9f41335004814490d65 Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Tue, 30 Apr 2019 14:39:55 +0200
Subject: [PATCH 5/5] Remove unused extern crate declatations
---
src/main.rs | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index c8bd1ef..c5aea70 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,8 +2,6 @@
extern crate actix_web;
#[macro_use]
extern crate lazy_static;
-extern crate reqwest;
-extern crate serde_json;
#[macro_use]
extern crate serde_derive;