Skip to content

Commit

Permalink
Add support for Github Workflow badges (#39)
Browse files Browse the repository at this point in the history
* Add support for Github Workflow badges

* Replace deprecated `trim_right` with `trim_end`
  • Loading branch information
scattenlaeufer committed Jan 31, 2020
1 parent 433e680 commit 82c2562
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/config/badges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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>;

Expand Down Expand Up @@ -77,6 +78,22 @@ pub fn travis_ci(attrs: Attrs) -> String {
)
}

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!(
"[![Workflow Status](https://github.com/{repo}/workflows/{workflow}/badge.svg)]\
(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
Expand Down
9 changes: 5 additions & 4 deletions src/config/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ fn process_badges(badges: BTreeMap<String, BTreeMap<String, String>>) -> Vec<Str
"circle-ci" => Some((1, badges::circle_ci(attrs))),
"gitlab" => Some((2, badges::gitlab(attrs))),
"travis-ci" => Some((3, badges::travis_ci(attrs))),
"codecov" => Some((4, badges::codecov(attrs))),
"coveralls" => Some((5, badges::coveralls(attrs))),
"github" => Some((4, badges::github(attrs))),
"codecov" => Some((5, badges::codecov(attrs))),
"coveralls" => Some((6, badges::coveralls(attrs))),
"is-it-maintained-issue-resolution" => {
Some((6, badges::is_it_maintained_issue_resolution(attrs)))
Some((7, badges::is_it_maintained_issue_resolution(attrs)))
}
"is-it-maintained-open-issues" => {
Some((7, badges::is_it_maintained_open_issues(attrs)))
Some((8, badges::is_it_maintained_open_issues(attrs)))
}
_ => return None,
})
Expand Down

0 comments on commit 82c2562

Please sign in to comment.