use std::collections::BTreeMap;
use percent_encoding as pe;
const BADGE_BRANCH_DEFAULT: &str = "master";
const BADGE_SERVICE_DEFAULT: &str = "github";
const BADGE_WORKFLOW_DEFAULT: &str = "main";
type Attrs = BTreeMap<String, String>;
pub fn appveyor(attrs: Attrs) -> String {
let repo = &attrs["repository"];
let branch = attrs
.get("branch")
.map(|i| i.as_ref())
.unwrap_or(BADGE_BRANCH_DEFAULT);
let service = attrs
.get("service")
.map(|i| i.as_ref())
.unwrap_or(BADGE_SERVICE_DEFAULT);
format!(
"[]\
(https://ci.appveyor.com/project/{repo}/branch/{branch})",
repo=repo, branch=branch, service=service
)
}
pub fn circle_ci(attrs: Attrs) -> String {
let repo = &attrs["repository"];
let branch = attrs
.get("branch")
.map(|i| i.as_ref())
.unwrap_or(BADGE_BRANCH_DEFAULT);
let service = badge_service_short_name(
attrs
.get("service")
.map(|i| i.as_ref())
.unwrap_or(BADGE_SERVICE_DEFAULT),
);
format!(
"[]\
(https://circleci.com/{service}/{repo}/tree/{branch})",
repo = repo,
service = service,
branch = percent_encode(branch)
)
}
pub fn gitlab(attrs: Attrs) -> String {
let repo = &attrs["repository"];
let branch = attrs
.get("branch")
.map(|i| i.as_ref())
.unwrap_or(BADGE_BRANCH_DEFAULT);
format!(
"[]\
(https://gitlab.com/{repo}/commits/master)",
repo = repo,
branch = percent_encode(branch)
)
}
pub fn travis_ci(attrs: Attrs) -> String {
let repo = &attrs["repository"];
let branch = attrs
.get("branch")
.map(|i| i.as_ref())
.unwrap_or(BADGE_BRANCH_DEFAULT);
format!(
"[]\
(https://travis-ci.org/{repo})",
repo = repo,
branch = percent_encode(branch)
)
}
pub fn github(attrs: Attrs) -> String {
let repo = &attrs["repository"];
let workflow = attrs
.get("workflow")
.map(|i| i.as_ref())
.unwrap_or(BADGE_WORKFLOW_DEFAULT);
format!(
"[]\
(https://github.com/{repo}/actions?query=workflow%3A%22{workflow_plus}%22)",
repo = repo,
workflow = percent_encode(workflow),
workflow_plus = percent_encode(&str::replace(workflow, " ", "+"))
)
}
pub fn codecov(attrs: Attrs) -> String {
let repo = &attrs["repository"];
let branch = attrs
.get("branch")
.map(|i| i.as_ref())
.unwrap_or(BADGE_BRANCH_DEFAULT);
let service = badge_service_short_name(
attrs
.get("service")
.map(|i| i.as_ref())
.unwrap_or(BADGE_SERVICE_DEFAULT),
);
format!(
"[]\
(https://codecov.io/{service}/{repo})",
repo = repo,
branch = percent_encode(branch),
service = service
)
}
pub fn coveralls(attrs: Attrs) -> String {
let repo = &attrs["repository"];
let branch = attrs
.get("branch")
.map(|i| i.as_ref())
.unwrap_or(BADGE_BRANCH_DEFAULT);
let service = attrs
.get("service")
.map(|i| i.as_ref())
.unwrap_or(BADGE_SERVICE_DEFAULT);
format!(
"[]\
(https://coveralls.io/{service}/{repo}?branch={branch})",
repo = repo,
branch = percent_encode(branch),
service = service
)
}
pub fn is_it_maintained_issue_resolution(attrs: Attrs) -> String {
let repo = &attrs["repository"];
format!(
"[]\
(https://isitmaintained.com/project/{repo} \"Average time to resolve an issue\")",
repo=repo
)
}
pub fn is_it_maintained_open_issues(attrs: Attrs) -> String {
let repo = &attrs["repository"];
format!(
"[]\
(https://isitmaintained.com/project/{repo} \"Percentage of issues still open\")",
repo = repo
)
}
pub fn maintenance(attrs: Attrs) -> String {
let status = &attrs["status"];
let status_with_color = match status.as_ref() {
"actively-developed" => "activly--developed-brightgreen",
"passively-maintained" => "passively--maintained-yellowgreen",
"as-is" => "as--is-yellow",
"none" => "maintenance-none-lightgrey", "experimental" => "experimental-blue",
"looking-for-maintainer" => "looking--for--maintainer-darkblue", "deprecated" => "deprecated-red",
_ => "unknow-black",
};
format!(
"",
status = status_with_color
)
}
fn percent_encode(input: &str) -> pe::PercentEncode<'_> {
pe::utf8_percent_encode(input, pe::NON_ALPHANUMERIC)
}
fn badge_service_short_name(service: &str) -> &'static str {
match service {
"github" => "gh",
"bitbucket" => "bb",
"gitlab" => "gl",
_ => "gh",
}
}