mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 02:16:30 +00:00
add "unknown" svg badge to signal errors
This commit is contained in:
parent
f4fa88e204
commit
3d6ea4be6f
4 changed files with 21 additions and 10 deletions
1
assets/badges/unknown.svg
Normal file
1
assets/badges/unknown.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="146" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="146" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h85v20H0z"/><path fill="#9f9f9f" d="M85 0h61v20H85z"/><path fill="url(#b)" d="M0 0h146v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"><text x="435" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="750">dependencies</text><text x="435" y="140" transform="scale(.1)" textLength="750">dependencies</text><text x="1145" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">unknown</text><text x="1145" y="140" transform="scale(.1)" textLength="510">unknown</text></g> </svg>
|
After Width: | Height: | Size: 972 B |
|
@ -4,6 +4,8 @@ pub static BADGE_UPTODATE_SVG: &'static [u8; 978] =
|
|||
include_bytes!("../../assets/badges/up-to-date.svg");
|
||||
pub static BADGE_OUTDATED_SVG: &'static [u8; 974] =
|
||||
include_bytes!("../../assets/badges/outdated.svg");
|
||||
pub static BADGE_UNKNOWN_SVG: &'static [u8; 972] =
|
||||
include_bytes!("../../assets/badges/unknown.svg");
|
||||
|
||||
pub static STATIC_STYLE_CSS: &'static str =
|
||||
include_str!(concat!(env!("OUT_DIR"), "/style.css"));
|
||||
|
|
|
@ -13,7 +13,7 @@ mod views;
|
|||
use ::engine::{Engine, AnalyzeDependenciesOutcome};
|
||||
use ::models::repo::RepoPath;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum StatusFormat {
|
||||
Html,
|
||||
Json,
|
||||
|
@ -101,10 +101,14 @@ impl Server {
|
|||
future::Either::B(server.engine.analyze_dependencies(repo_path.clone()).then(move |analyze_result| {
|
||||
match analyze_result {
|
||||
Err(err) => {
|
||||
if format != StatusFormat::Svg {
|
||||
let mut response = Response::new();
|
||||
response.set_status(StatusCode::InternalServerError);
|
||||
response.set_status(StatusCode::BadRequest);
|
||||
response.set_body(format!("{:?}", err));
|
||||
future::Either::A(future::ok(response))
|
||||
} else {
|
||||
future::Either::A(future::ok(views::status_svg(None)))
|
||||
}
|
||||
},
|
||||
Ok(analysis_outcome) => {
|
||||
let response = Server::status_format_analysis(analysis_outcome, format, repo_path);
|
||||
|
@ -122,7 +126,7 @@ impl Server {
|
|||
StatusFormat::Json =>
|
||||
views::status_json(analysis_outcome),
|
||||
StatusFormat::Svg =>
|
||||
views::status_svg(analysis_outcome),
|
||||
views::status_svg(Some(analysis_outcome)),
|
||||
StatusFormat::Html =>
|
||||
views::html::status::render(analysis_outcome, repo_path)
|
||||
}
|
||||
|
|
|
@ -4,13 +4,17 @@ use hyper::header::ContentType;
|
|||
use ::server::assets;
|
||||
use ::engine::AnalyzeDependenciesOutcome;
|
||||
|
||||
pub fn status_svg(analysis_outcome: AnalyzeDependenciesOutcome) -> Response {
|
||||
pub fn status_svg(analysis_outcome: Option<AnalyzeDependenciesOutcome>) -> Response {
|
||||
let mut response = Response::new()
|
||||
.with_header(ContentType("image/svg+xml;charset=utf-8".parse().unwrap()));
|
||||
if analysis_outcome.deps.any_outdated() {
|
||||
if let Some(outcome) = analysis_outcome {
|
||||
if outcome.deps.any_outdated() {
|
||||
response.set_body(assets::BADGE_OUTDATED_SVG.to_vec());
|
||||
} else {
|
||||
response.set_body(assets::BADGE_UPTODATE_SVG.to_vec());
|
||||
}
|
||||
} else {
|
||||
response.set_body(assets::BADGE_UNKNOWN_SVG.to_vec());
|
||||
}
|
||||
response
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue