Added a gateway that can save the current state, so it can be read again and again without calling github all the time
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Martin Slot 2022-12-18 11:23:20 +01:00
parent ff511887db
commit eb7114c157
1 changed files with 26 additions and 6 deletions

View File

@ -1,11 +1,13 @@
use std::cmp::Ordering;
use std::time::Duration;
use reqwest::header::ACCEPT;
use crate::configuration::VcsType;
use crate::request::models::{Current, GithubRelease, State};
use crate::request::notification::Notification;
use crate::request::versioning::{SemverVersionComparer, VersionComparer};
use crate::{Print, Settings};
use reqwest::header::ACCEPT;
use std::cmp::Ordering;
use std::time::Duration;
pub fn init<'a>(
settings: &'a Settings,
@ -13,10 +15,12 @@ pub fn init<'a>(
notification: &'a dyn Notification,
) -> RequestHandler<'a> {
let request_gateway = RequestGateway::new(settings, notification);
let state_gateway = StateGateway::new(settings);
RequestHandler {
settings,
request_gateway,
console,
state_gateway,
}
}
@ -24,6 +28,7 @@ pub struct RequestHandler<'a> {
pub settings: &'a Settings,
console: &'a dyn Print,
request_gateway: RequestGateway<'a>,
state_gateway: StateGateway<'a>,
}
pub struct RequestGateway<'a> {
@ -31,6 +36,18 @@ pub struct RequestGateway<'a> {
pub notification: &'a dyn Notification,
}
pub struct StateGateway<'a> {
settings: &'a Settings,
}
impl<'a> StateGateway {
fn new(settings: &Settings) -> StateGateway {
StateGateway { settings }
}
pub fn save_state(&self, states: Vec<State>) {}
}
impl<'a> RequestHandler<'a> {
pub fn execute(&self) {
let currents = self.request_gateway.get_currents();
@ -138,10 +155,11 @@ JOIN VcsTypes V ON O.vcs_type = V.vcs_type";
}
pub mod notification {
use crate::request::models::State;
use lettre::transport::smtp::authentication::Credentials;
use lettre::{Message, SmtpTransport, Transport};
use crate::request::models::State;
pub trait Notification {
fn send(&self, currents: &Vec<State>);
}
@ -186,9 +204,10 @@ pub mod notification {
}
mod versioning {
use semver::Version;
use std::cmp::Ordering;
use semver::Version;
pub trait VersionComparer {
fn compare(&self, v1: &str, v2: &str) -> Ordering;
}
@ -254,9 +273,10 @@ pub mod models {
#[cfg(test)]
mod tests {
use crate::request::versioning::{SemverVersionComparer, VersionComparer};
use std::cmp::Ordering;
use crate::request::versioning::{SemverVersionComparer, VersionComparer};
#[test]
fn rest_equal_semver() {
let comparer = SemverVersionComparer;