Skip to content

Commit

Permalink
feat: Correctly handle active support without known end
Browse files Browse the repository at this point in the history
  • Loading branch information
bbastin committed Aug 1, 2024
1 parent 6b38871 commit a708c5f
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 72 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.10.0] - 2024-08-01

### <!-- 1 -->Added

- Correctly handle active support without known end

### <!-- 2 -->Changed

- Updated CHANGELOG.md

## [0.9.0] - 2024-08-01

### <!-- 1 -->Added
Expand Down Expand Up @@ -99,6 +109,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial commit

[0.10.0]: https://github.com/bbastin/assetinfo/compare/v0.9.0..v0.10.0
[0.9.0]: https://github.com/bbastin/assetinfo/compare/v0.8.0..v0.9.0
[0.8.0]: https://github.com/bbastin/assetinfo/compare/v0.7.0..v0.8.0
[0.7.0]: https://github.com/bbastin/assetinfo/compare/v0.6.2..v0.7.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[package]
name = "assetinfo"
version = "0.9.0"
version = "0.10.0"
authors = ["Benedikt Bastin"]
edition = "2021"
description = "assetinfo is a tool to watch for versions of assets and their end-of-life date."
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use assetinfo::{
db::Database,
program::{Extractor, Program, ProgramInfo, Version},
providers::endoflife_date::{self, Eol, ReleaseCycle},
providers::endoflife_date::{self, DateOrBool, ReleaseCycle},
};
use chrono::{TimeDelta, Utc};
use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -122,7 +122,7 @@ async fn print_info<T: Extractor>(e: T, p: &ProgramInfo) -> Result<(), Box<dyn E
}

fn print_end_of_life_info(v: &Version, cycle_info: &ReleaseCycle) {
if let Eol::Date(eol_date) = cycle_info.eol {
if let DateOrBool::Date(eol_date) = cycle_info.eol {
let today = Utc::now().date_naive();

let remaining_time = eol_date - today;
Expand Down
11 changes: 2 additions & 9 deletions src/providers/endoflife_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ pub enum CycleId {
Number(i64),
}

#[derive(Deserialize, PartialEq, Eq, Debug, Clone)]
#[serde(untagged)]
pub enum Eol {
Date(NaiveDate),
String(String),
}

#[derive(Deserialize, PartialEq, Eq, Debug, Clone)]
#[serde(untagged)]
pub enum Lts {
Expand All @@ -40,7 +33,7 @@ pub enum DateOrBool {
pub struct ReleaseCycle {
pub cycle: Option<CycleId>,
pub release_date: NaiveDate,
pub eol: Eol,
pub eol: DateOrBool,
pub latest: String,
pub link: Option<String>,
pub lts: Lts,
Expand Down Expand Up @@ -106,7 +99,7 @@ mod tests {
);
assert_eq!(
rc.eol,
Eol::Date(NaiveDate::from_ymd_opt(2022, 01, 01).unwrap())
DateOrBool::Date(NaiveDate::from_ymd_opt(2022, 01, 01).unwrap())
);
assert_eq!(rc.latest, "21.04");
assert_eq!(
Expand Down
142 changes: 83 additions & 59 deletions src/table_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

use assetinfo::{
program::{Extractor, Program, ProgramInfo, Version},
providers::endoflife_date::{self, CycleId, DateOrBool, Eol, ReleaseCycle},
providers::endoflife_date::{self, CycleId, DateOrBool, ReleaseCycle},
};
use chrono::Utc;
use std::error::Error;
use tabled::{
settings::{object::Rows, themes::Colorization, Color, Panel, Style},
Expand Down Expand Up @@ -56,6 +55,8 @@ struct ProgramDisplayVersion {
version: String,
#[tabled(rename = "Release Cycle")]
cycle: String,
#[tabled(rename = "Supported")]
supported: String,
#[tabled(rename = "Updates until")]
updates_until: String,
#[tabled(rename = "Security Updates until")]
Expand All @@ -68,48 +69,64 @@ fn version_row(
r: &Option<ReleaseCycle>,
source: &str,
) -> ProgramDisplayVersion {
let today = Utc::now().date_naive();
let today = chrono::Utc::now().date_naive();

let security_until = match r {
match r {
Some(r) => {
if let Eol::Date(eol_date) = r.eol {
let remaining_time = eol_date - today;
let (security_until, supported) = match &r.eol {
DateOrBool::Date(eol_date) => {
let remaining_time = *eol_date - today;
let supported = if remaining_time.num_days() > 0 {
"Yes".to_string()
} else {
"No".to_string()
};

format!("{} ({} days)", eol_date, remaining_time.num_days(),)
} else {
"Unknown".to_string()
(
format!("{} ({} days)", eol_date, remaining_time.num_days(),),
supported,
)
}
DateOrBool::Bool(eol) => {
if *eol {
("No".to_string(), "No".to_string())
} else {
("Unknown".to_string(), "Yes".to_string())
}
}
};
let updates_until = match r.support {
Some(DateOrBool::Date(date)) => {
let remaining_time = date - today;
format!("{} ({} days)", date, remaining_time.num_days(),)
}
Some(DateOrBool::Bool(supported)) => {
format!("{supported}")
}
None => security_until.clone(),
};

let cycle = format!("{} ({})", v.cycle, r.latest);

ProgramDisplayVersion {
title: p.title.clone(),
source: source.to_string(),
version: v.string.clone(),
cycle,
supported,
updates_until,
security_until,
}
}
None => "Unknown".to_string(),
};

let updates_until = match r {
Some(r) => match r.support {
Some(DateOrBool::Date(date)) => {
let remaining_time = date - today;
format!("{} ({} days)", date, remaining_time.num_days(),)
}
Some(DateOrBool::Bool(supported)) => {
format!("{supported}")
}
None => security_until.clone(),
None => ProgramDisplayVersion {
title: p.title.clone(),
source: source.to_string(),
version: v.string.clone(),
cycle: v.cycle.clone(),
supported: "Unknown".to_string(),
updates_until: "Unknown".to_string(),
security_until: "Unknown".to_string(),
},
None => security_until.clone(),
};

let cycle = if let Some(r) = r {
format!("{} ({})", v.cycle, r.latest)
} else {
v.cycle.clone()
};

ProgramDisplayVersion {
title: p.title.clone(),
source: source.to_string(),
version: v.string.clone(),
cycle,
updates_until,
security_until,
}
}

Expand Down Expand Up @@ -137,32 +154,39 @@ async fn get_release_cycle(p: &ProgramInfo, v: &Version) -> Option<ReleaseCycle>

fn get_display_release_cycle(release_cycle: &Option<ReleaseCycle>) -> SupportState {
if let Some(release_cycle) = release_cycle {
let today = Utc::now().date_naive();

if let Eol::Date(eol) = release_cycle.eol {
if eol < today {
SupportState::Unsupported
} else {
match release_cycle.support {
Some(DateOrBool::Date(supported_until)) => {
if supported_until < today {
SupportState::Security
} else {
SupportState::Supported
let today = chrono::Utc::now().date_naive();

match release_cycle.eol {
DateOrBool::Date(eol) => {
if eol < today {
SupportState::Unsupported
} else {
match release_cycle.support {
Some(DateOrBool::Date(supported_until)) => {
if supported_until < today {
SupportState::Security
} else {
SupportState::Supported
}
}
}
Some(DateOrBool::Bool(is_supported)) => {
if is_supported {
SupportState::Supported
} else {
SupportState::Security
Some(DateOrBool::Bool(is_supported)) => {
if is_supported {
SupportState::Supported
} else {
SupportState::Security
}
}
None => SupportState::Supported,
}
None => SupportState::Supported,
}
}
} else {
SupportState::Supported
DateOrBool::Bool(eol) => {
if eol {
SupportState::Unsupported
} else {
SupportState::Supported
}
}
}
} else {
SupportState::Unknown
Expand Down

0 comments on commit a708c5f

Please sign in to comment.