Improve detection of "unknown" travis builds

pull/831/head
Tom Parker-Shemilt 5 years ago
parent 584d8fca82
commit ecd6658ec6

@ -81,7 +81,7 @@ lazy_static! {
static ref HANDLES: MaxHandles = MaxHandles::new(20); static ref HANDLES: MaxHandles = MaxHandles::new(20);
} }
fn get_url(url: String) -> BoxFuture<'static, (String, Result<String, CheckerError>)> { fn get_url(url: String) -> BoxFuture<'static, (String, Result<(), CheckerError>)> {
async move { async move {
let _handle = HANDLES.get().await; let _handle = HANDLES.get().await;
let mut res = Err(CheckerError::NotTried); let mut res = Err(CheckerError::NotTried);
@ -98,7 +98,7 @@ fn get_url(url: String) -> BoxFuture<'static, (String, Result<String, CheckerErr
res = Err(CheckerError::ReqwestError{error: err}); res = Err(CheckerError::ReqwestError{error: err});
continue; continue;
} }
Ok(ref ok) => { Ok(ok) => {
let status = ok.status(); let status = ok.status();
if status != StatusCode::OK { if status != StatusCode::OK {
lazy_static! { lazy_static! {
@ -143,15 +143,16 @@ fn get_url(url: String) -> BoxFuture<'static, (String, Result<String, CheckerErr
static ref TRAVIS_IMG_REGEX: Regex = Regex::new(r"https://api.travis-ci.(?:com|org)/[^/]+/.+\.svg").unwrap(); static ref TRAVIS_IMG_REGEX: Regex = Regex::new(r"https://api.travis-ci.(?:com|org)/[^/]+/.+\.svg").unwrap();
} }
if TRAVIS_IMG_REGEX.is_match(&url) { 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(""); // Previously we checked the Content-Disposition headers, but sometimes that is incorrect
debug!("Content dispostion for {} is '{}'", content_dispostion, url); // We're now looking for the explicit text "unknown" in the middle of the SVG
if content_dispostion == "inline; filename=\"unknown.svg\"" { let content = ok.text().await.unwrap();
if content.contains("unknown") {
res = Err(CheckerError::TravisBuildUnknown); res = Err(CheckerError::TravisBuildUnknown);
break; break;
} }
} }
debug!("Finished {}", url); debug!("Finished {}", url);
res = Ok(format!("{:?}", ok)); res = Ok(());
break; break;
} }
} }

Loading…
Cancel
Save