Added a simple formatted text for the email
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Martin Slot 2022-12-13 14:44:23 +01:00
parent 8c47fe4270
commit 418f373c98
2 changed files with 41 additions and 11 deletions

View File

@ -8,7 +8,7 @@ use config::{Config, ConfigError, Environment, File};
use rusqlite::{Connection, OpenFlags};
use serde::Deserialize;
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum VcsType {
Unknown,
Github,

View File

@ -1,5 +1,5 @@
use crate::configuration::VcsType;
use crate::request::models::{Current, GithubRelease};
use crate::request::models::{Current, GithubRelease, State};
use crate::request::notification::Notification;
use crate::request::versioning::{SemverVersionComparer, VersionComparer};
use crate::{Print, Settings};
@ -36,7 +36,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();
let mut send_alerts_for = Vec::<State>::new();
for current in currents.iter() {
//TODO: This needs to be rethought a bit
@ -86,7 +86,7 @@ impl<'a> RequestHandler<'a> {
let ordering = comparer.compare(current_version, origin_version.as_str());
if ordering == Ordering::Less {
send_alerts_for.push(current);
send_alerts_for.push(State::new(release, current.clone()));
} else {
println!(
"Current version for {:?} is alligned with or larger than CVS",
@ -96,7 +96,7 @@ impl<'a> RequestHandler<'a> {
}
if !send_alerts_for.is_empty() {
self.request_gateway.notification.send(&currents);
self.request_gateway.notification.send(&send_alerts_for);
}
}
}
@ -143,12 +143,13 @@ JOIN VcsTypes V ON O.vcs_type = V.vcs_type";
}
pub mod notification {
use crate::request::models::Current;
use crate::request::models::{Current, State};
use lettre::transport::smtp::authentication::Credentials;
use lettre::{Message, SmtpTransport, Transport};
use std::thread::current;
pub trait Notification {
fn send(&self, currents: &Vec<Current>);
fn send(&self, currents: &Vec<State>);
}
pub struct EmailNotification {
@ -159,13 +160,16 @@ pub mod notification {
}
impl Notification for EmailNotification {
fn send(&self, currents: &Vec<Current>) {
for current in currents {
fn send(&self, states: &Vec<State>) {
for state in states {
let email = Message::builder()
.from(self.from.parse().unwrap())
.to(current.contact.parse().unwrap())
.to(state.current.contact.parse().unwrap())
.subject("Version checker: something has changed")
.body(String::from("")) // TODO: we need something clever here :)
.body(String::from(format!(
"current version for {} is {} but on Github it is {}",
state.current.name, state.current.version, state.release.tag_name
)))
.unwrap();
let creds = Credentials::new(
@ -216,6 +220,17 @@ pub mod models {
pub name: String,
}
pub struct State {
pub current: Current,
pub release: GithubRelease,
}
impl State {
pub fn new(release: GithubRelease, current: Current) -> State {
State { current, release }
}
}
#[derive(Debug)]
pub struct Current {
pub name: String,
@ -226,6 +241,21 @@ pub mod models {
pub version: String,
pub contact: String,
}
// TODO: is this the correct way of understanding how clone should be used? Is this the correct way of cloning a string, by calling to_owned?
impl Clone for Current {
fn clone(&self) -> Self {
Current {
name: self.name.to_owned(),
owner_name: self.owner_name.to_owned(),
repo_name: self.repo_name.to_owned(),
vcs_type: self.vcs_type,
api_root_url: self.api_root_url.to_owned(),
version: self.version.to_owned(),
contact: self.contact.to_owned(),
}
}
}
}
#[cfg(test)]