From 558137e2ee276371e584ff1dde4b3d83b511751f Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Mon, 16 Jan 2023 09:54:04 +0100
Subject: [PATCH 1/3] Allow customization of the badge label
---
src/lib.rs | 25 +++++++++++++++++--------
templates/index.rs.html | 4 ++++
templates/overview.rs.html | 4 ++--
3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
index 178d239..888ba20 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -83,8 +83,14 @@ struct JsonResponse<'a> {
}
#[derive(Deserialize, Debug)]
-struct BranchQuery {
+struct BadgeQuery {
branch: Option,
+ #[serde(default = "default_label")]
+ label: String,
+}
+
+fn default_label() -> String {
+ "Hits-of-Code".to_string()
}
fn pull(path: impl AsRef) -> Result<()> {
@@ -298,7 +304,7 @@ pub(crate) async fn json_hoc(
state: web::Data,
repo_count: web::Data,
data: web::Path<(String, String)>,
- branch: web::Query,
+ branch: web::Query,
) -> Result {
let branch = branch.branch.as_deref().unwrap_or("master");
let rc_clone = repo_count.clone();
@@ -334,14 +340,15 @@ pub(crate) async fn calculate_hoc(
state: web::Data,
repo_count: web::Data,
data: web::Path<(String, String)>,
- branch: web::Query,
+ query: web::Query,
) -> HttpResponse {
let rc_clone = repo_count.clone();
+ let label = query.label.clone();
let mapper = move |r| match r {
HocResult::NotFound => p404(rc_clone),
HocResult::Hoc { hoc_pretty, .. } => {
let badge_opt = BadgeOptions {
- subject: "Hits-of-Code".to_string(),
+ subject: label,
color: "#007ec6".to_string(),
status: hoc_pretty,
};
@@ -352,10 +359,10 @@ pub(crate) async fn calculate_hoc(
Ok(no_cache_response(body))
}
};
- let branch = branch.branch.as_deref().unwrap_or("master");
+ let branch = query.branch.as_deref().unwrap_or("master");
let error_badge = |_| {
let error_badge = Badge::new(BadgeOptions {
- subject: "Hits-of-Code".to_string(),
+ subject: query.label.clone(),
color: "#ff0000".to_string(),
status: "error".to_string(),
})
@@ -372,9 +379,10 @@ async fn overview(
state: web::Data,
repo_count: web::Data,
data: web::Path<(String, String)>,
- branch: web::Query,
+ query: web::Query,
) -> Result {
- let branch = branch.branch.as_deref().unwrap_or("master");
+ let branch = query.branch.as_deref().unwrap_or("master");
+ let label = query.label.clone();
let base_url = state.settings.base_url.clone();
let rc_clone = repo_count.clone();
let mapper = move |r| match r {
@@ -405,6 +413,7 @@ async fn overview(
VERSION_INFO,
rc_clone.load(Ordering::Relaxed),
repo_info,
+ label,
)?;
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
diff --git a/templates/index.rs.html b/templates/index.rs.html
index aebc661..75934d4 100644
--- a/templates/index.rs.html
+++ b/templates/index.rs.html
@@ -51,6 +51,10 @@ in your repository or you want a badge for another branch of your repository, ju
?branch=<branch-name>
to the URL.
+
+The badge label can be customized using the label=<some-label>
query parameter. It defaults to Hits-of-Code
.
+
+
You can also request the HoC as JSON by appending /json
to the request path. This will return a JSON object
with three fields: count
(the HoC value), commits
(the number of commits) and
diff --git a/templates/overview.rs.html b/templates/overview.rs.html
index 13bc9e1..ef209a1 100644
--- a/templates/overview.rs.html
+++ b/templates/overview.rs.html
@@ -2,7 +2,7 @@
@use crate::statics::VersionInfo;
@use crate::template::RepoInfo;
-@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo)
+@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo, label: String)
@:base("Hits-of-Code Badges", "Overview", {
@@ -19,7 +19,7 @@ To include the badge in your readme, use the following markdown:
-[![Hits-of-Code](@repo_info.base_url/@repo_info.path?branch=@repo_info.branch)](@repo_info.base_url/@repo_info.path/view?branch=@repo_info.branch)
+[![@label](@repo_info.base_url/@repo_info.path?branch=@repo_info.branch&label=@label)](@repo_info.base_url/@repo_info.path/view?branch=@repo_info.branch&label=@label)
From 665db0b8c5b6940ef240cb3cc652d433ca5c8d1e Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Mon, 16 Jan 2023 09:59:52 +0100
Subject: [PATCH 2/3] Update changelog
---
CHANGELOG.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1066eac..2249495 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### New Features
+
+* Allow customization of the badge label ([#546])
+
### Dependency Updates
* Updated [`tracing-actix-web`](https://github.com/LukeMathWalker/tracing-actix-web) from 0.7.1 to 0.7.2 ([#542])
@@ -13,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#542]: https://github.com/vbrandl/hoc/pull/542
[#544]: https://github.com/vbrandl/hoc/pull/544
+[#546]: https://github.com/vbrandl/hoc/pull/546
## [0.29.0] 2023-01-07
From 30906da8035aa039865a2fccc234778bea0f8ccd Mon Sep 17 00:00:00 2001
From: Valentin Brandl
Date: Mon, 16 Jan 2023 10:02:36 +0100
Subject: [PATCH 3/3] Bump version (v0.30.0)
---
CHANGELOG.md | 3 +++
Cargo.lock | 2 +-
Cargo.toml | 2 +-
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2249495..2b82ed8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+
+## [0.30.0] 2023-01-16
+
### New Features
* Allow customization of the badge label ([#546])
diff --git a/Cargo.lock b/Cargo.lock
index 3c81587..18d3088 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -895,7 +895,7 @@ dependencies = [
[[package]]
name = "hoc"
-version = "0.29.0"
+version = "0.30.0"
dependencies = [
"actix-rt",
"actix-web",
diff --git a/Cargo.toml b/Cargo.toml
index 5d427c6..d6aa7c0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "hoc"
-version = "0.29.0"
+version = "0.30.0"
authors = ["Valentin Brandl "]
edition = "2018"
build = "build.rs"