mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 18:36:30 +00:00
display number of outdated dependencies in badge
This commit is contained in:
parent
1c4f933887
commit
12e4d7df51
4 changed files with 35 additions and 4 deletions
|
@ -126,7 +126,7 @@ impl Badge {
|
||||||
})
|
})
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or(0.0);
|
.unwrap_or(0.0);
|
||||||
(width + ((text.len() as f32 - 1f32) * 1.5)).ceil() as u32
|
(width + ((text.len() as f32 - 1f32) * 1.3)).ceil() as u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,12 @@ impl AnalyzeDependenciesOutcome {
|
||||||
pub fn any_outdated(&self) -> bool {
|
pub fn any_outdated(&self) -> bool {
|
||||||
self.crates.iter().any(|&(_, ref deps)| deps.any_outdated())
|
self.crates.iter().any(|&(_, ref deps)| deps.any_outdated())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn outdated_ratio(&self) -> (usize, usize) {
|
||||||
|
self.crates.iter().fold((0, 0), |(outdated, total), &(_, ref deps)| {
|
||||||
|
(outdated + deps.count_outdated(), total + deps.count_total())
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
|
|
|
@ -127,6 +127,23 @@ impl AnalyzedDependencies {
|
||||||
AnalyzedDependencies { main, dev, build }
|
AnalyzedDependencies { main, dev, build }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn count_total(&self) -> usize {
|
||||||
|
self.main.len() + self.dev.len() + self.build.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn count_outdated(&self) -> usize {
|
||||||
|
let main_outdated = self.main.iter()
|
||||||
|
.filter(|&(_, dep)| dep.is_outdated())
|
||||||
|
.count();
|
||||||
|
let dev_outdated = self.dev.iter()
|
||||||
|
.filter(|&(_, dep)| dep.is_outdated())
|
||||||
|
.count();
|
||||||
|
let build_outdated = self.build.iter()
|
||||||
|
.filter(|&(_, dep)| dep.is_outdated())
|
||||||
|
.count();
|
||||||
|
main_outdated + dev_outdated + build_outdated
|
||||||
|
}
|
||||||
|
|
||||||
pub fn any_outdated(&self) -> bool {
|
pub fn any_outdated(&self) -> bool {
|
||||||
let main_any_outdated = self.main.iter()
|
let main_any_outdated = self.main.iter()
|
||||||
.any(|(_, dep)| dep.is_outdated());
|
.any(|(_, dep)| dep.is_outdated());
|
||||||
|
|
|
@ -7,16 +7,24 @@ use ::engine::AnalyzeDependenciesOutcome;
|
||||||
pub fn badge(analysis_outcome: Option<&AnalyzeDependenciesOutcome>) -> Badge {
|
pub fn badge(analysis_outcome: Option<&AnalyzeDependenciesOutcome>) -> Badge {
|
||||||
let opts = match analysis_outcome {
|
let opts = match analysis_outcome {
|
||||||
Some(outcome) => {
|
Some(outcome) => {
|
||||||
if outcome.any_outdated() {
|
let (outdated, total) = outcome.outdated_ratio();
|
||||||
|
|
||||||
|
if outdated > 0 {
|
||||||
BadgeOptions {
|
BadgeOptions {
|
||||||
subject: "dependencies".into(),
|
subject: "dependencies".into(),
|
||||||
status: "outdated".into(),
|
status: format!("{} of {} outdated", outdated, total),
|
||||||
color: "#dfb317".into()
|
color: "#dfb317".into()
|
||||||
}
|
}
|
||||||
|
} else if total > 0 {
|
||||||
|
BadgeOptions {
|
||||||
|
subject: "dependencies".into(),
|
||||||
|
status: "up to date".into(),
|
||||||
|
color: "#4c1".into()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
BadgeOptions {
|
BadgeOptions {
|
||||||
subject: "dependencies".into(),
|
subject: "dependencies".into(),
|
||||||
status: "up to date".into(),
|
status: "none".into(),
|
||||||
color: "#4c1".into()
|
color: "#4c1".into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue