1
0
mirror of https://github.com/rust-unofficial/awesome-rust.git synced 2025-01-29 22:01:07 +02:00

Catch github actions badges with no branch

This commit is contained in:
Tom Parker-Shemilt 2020-02-12 23:20:58 +00:00
parent d17daf5187
commit 5bceef3656

View File

@ -32,6 +32,9 @@ enum CheckerError {
#[fail(display = "travis build is unknown")]
TravisBuildUnknown,
#[fail(display = "github actions image with no branch")]
GithubActionNoBranch,
}
struct MaxHandles {
@ -141,6 +144,7 @@ fn get_url(url: String) -> BoxFuture<'static, (String, Result<String, CheckerErr
}
lazy_static! {
static ref TRAVIS_IMG_REGEX: Regex = Regex::new(r"https://api.travis-ci.(?:com|org)/[^/]+/.+\.svg").unwrap();
static ref GITHUB_ACTIONS_REGEX: Regex = Regex::new(r"https://github.com/[^/]+/[^/]+/workflows/[^/]+/badge.svg(\?.+)?").unwrap();
}
if TRAVIS_IMG_REGEX.is_match(&url) {
let content_dispostion = ok.headers().get(header::CONTENT_DISPOSITION).and_then(|h| h.to_str().ok()).unwrap_or("");
@ -150,6 +154,14 @@ fn get_url(url: String) -> BoxFuture<'static, (String, Result<String, CheckerErr
break;
}
}
if let Some(matches) = GITHUB_ACTIONS_REGEX.captures(&url) {
debug!("Github actions match {:?}", matches);
let query = matches.get(1).map(|x| x.as_str()).unwrap_or("");
if !query.starts_with("?") || query.find("branch=").is_none() {
res = Err(CheckerError::GithubActionNoBranch);
break;
}
}
debug!("Finished {}", url);
res = Ok(format!("{:?}", ok));
break;
@ -254,6 +266,9 @@ async fn main() -> Result<(), Error> {
CheckerError::TravisBuildUnknown => {
format!("[Unknown travis build] {}", url)
}
CheckerError::GithubActionNoBranch => {
format!("[Github action image with no branch specified] {}", url)
}
_ => {
format!("{:?}", err)
}