Added ordering check
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
This commit is contained in:
parent
3e595f69a0
commit
4cab9930b4
|
@ -1,6 +1,8 @@
|
|||
use crate::configuration::VcsType;
|
||||
use crate::request::models::{Current, GithubRelease};
|
||||
use crate::request::versioning::{SemverVersionComparer, VersionComparer};
|
||||
use crate::{Print, Settings};
|
||||
use std::cmp::Ordering;
|
||||
|
||||
pub fn init<'a>(settings: &'a Settings, console: &'a dyn Print) -> RequestHandler<'a> {
|
||||
let request_gateway = RequestGateway::new(settings);
|
||||
|
@ -24,6 +26,7 @@ pub struct RequestGateway<'a> {
|
|||
impl<'a> RequestHandler<'a> {
|
||||
pub fn execute(&self) {
|
||||
let currents = self.request_gateway.get_currents();
|
||||
let mut send_alerts_for = Vec::<&Current>::new();
|
||||
|
||||
for current in currents.iter() {
|
||||
//TODO: This needs to be rethought a bit
|
||||
|
@ -43,8 +46,19 @@ impl<'a> RequestHandler<'a> {
|
|||
.json::<GithubRelease>()
|
||||
.unwrap();
|
||||
|
||||
// compare
|
||||
println!("Got release {:?}", release);
|
||||
// Compare
|
||||
// For now we only have one comparer: semver comparer, so it is hardcoded here. This is going to be changed when more is added
|
||||
let comparer = SemverVersionComparer;
|
||||
let ordering = comparer.compare(current.version.as_str(), release.tag_name.as_str());
|
||||
|
||||
if ordering == Ordering::Less {
|
||||
send_alerts_for.push(current);
|
||||
} else {
|
||||
println!(
|
||||
"Current version for {:?} is alligned with or larger than CVS",
|
||||
current
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// send alerts
|
||||
|
@ -60,7 +74,7 @@ impl<'a> RequestGateway<'a> {
|
|||
let connection = self.settings.database.get_connection();
|
||||
|
||||
let sql = "
|
||||
SELECT C.name, C.vcs_type, V.api_root_url, O.OWNER_NAME, O.REPO_NAME
|
||||
SELECT C.name, C.vcs_type, V.api_root_url, O.owner_name, O.repo_name, C.version
|
||||
FROM Origins O
|
||||
JOIN Currents C ON O.name = C.name AND O.vcs_type = C.vcs_type
|
||||
JOIN VCSTYPES V ON O.vcs_type = V.vcs_type";
|
||||
|
@ -79,6 +93,7 @@ JOIN VCSTYPES V ON O.vcs_type = V.vcs_type";
|
|||
api_root_url: row.get(2).unwrap(),
|
||||
owner_name: row.get(3).unwrap(),
|
||||
repo_name: row.get(4).unwrap(),
|
||||
version: row.get(5).unwrap(),
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
|
@ -116,12 +131,14 @@ pub mod models {
|
|||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Current {
|
||||
pub name: String,
|
||||
pub owner_name: String,
|
||||
pub repo_name: String,
|
||||
pub vcs_type: VcsType,
|
||||
pub api_root_url: String,
|
||||
pub version: String,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue