Allow providing a branch name in generator

This commit is contained in:
Valentin Brandl 2022-08-18 14:07:07 +02:00
parent ecbc63f522
commit dbbbdad3fa
No known key found for this signature in database
GPG Key ID: 62E7C7F2C48DBBF2
3 changed files with 11 additions and 3 deletions

View File

@ -55,6 +55,7 @@ struct GeneratorForm<'a> {
service: FormService, service: FormService,
user: Cow<'a, str>, user: Cow<'a, str>,
repo: Cow<'a, str>, repo: Cow<'a, str>,
branch: Option<Cow<'a, str>>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -447,6 +448,11 @@ async fn generate(
params.service.url(), params.service.url(),
params.service.service(), params.service.service(),
&repo, &repo,
params
.branch
.as_deref()
.filter(|s| !s.is_empty())
.unwrap_or("master"),
)?; )?;
Ok(HttpResponse::Ok().content_type("text/html").body(buf)) Ok(HttpResponse::Ok().content_type("text/html").body(buf))

View File

@ -1,7 +1,7 @@
@use super::base; @use super::base;
@use crate::statics::VersionInfo; @use crate::statics::VersionInfo;
@(version_info: VersionInfo, repo_count: usize, base_url: &str, url: &str, service: &str, path: &str) @(version_info: VersionInfo, repo_count: usize, base_url: &str, url: &str, service: &str, path: &str, branch: &str)
@:base("Hits-of-Code Badges", "Badge Generator", { @:base("Hits-of-Code Badges", "Badge Generator", {
@ -10,7 +10,7 @@ Here is the markdown for the badge for <a href="https://@url/@path">@url/@path</
</p> </p>
<pre> <pre>
[![Hits-of-Code](@base_url/@service/@path)](@base_url/@service/@path/view) [![Hits-of-Code](@base_url/@service/@path?branch=@branch)](@base_url/@service/@path/view?branch=@branch)
</pre> </pre>
<p> <p>
@ -18,6 +18,6 @@ It will be rendered like this
</p> </p>
<pre> <pre>
<a href="@base_url/@service/@path/view"><img src="@base_url/@service/@path" alt="example badge" /></a> <a href="@base_url/@service/@path/view?branch=@branch"><img src="@base_url/@service/@path?branch=@branch" alt="example badge" /></a>
</pre> </pre>
}, version_info, repo_count) }, version_info, repo_count)

View File

@ -80,6 +80,8 @@ the lines of
<input name="user" id="user" type="text" placeholder="user" /> <input name="user" id="user" type="text" placeholder="user" />
<label>/</label> <label>/</label>
<input name="repo" id="repo" type="text" placeholder="repository" /> <input name="repo" id="repo" type="text" placeholder="repository" />
<label>:</label>
<input name="branch" id="branch" type="text" placeholder="branch (defaults to `master`)" />
<button type="submit">Generate</button> <button type="submit">Generate</button>
</form> </form>