cinderella

[unmaintained] simple CI engine
Log | Files | Refs | README | LICENSE

commit 1793fe25d4f8d30c3ac02583f26870e2a2368ce9
parent cdb7201767eacf348708e48d7142e18f2aa85924
Author: Stefan Koch <programming@stefan-koch.name>
Date:   Fri,  4 Oct 2019 22:15:56 +0200

add repo name to build failure mail

Diffstat:
Msrc/lib.rs | 15+++++++++++++--
Msrc/mail.rs | 8++++----
2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -22,6 +22,13 @@ pub struct RepoPointer { pub branch: Option<String>, } +impl RepoPointer { + // TODO: This approach only works for URLs, not for local paths. + fn name(&self) -> String { + self.repo_url.split('/').last().unwrap().to_string() + } +} + fn random_dir(base_path: &str) -> PathBuf { let mut tempdir = PathBuf::from(base_path); @@ -90,11 +97,15 @@ pub fn run(repo_ptr: &RepoPointer) { None => format!("Process terminated by signal") }; let mailer = mail::build_mailer(&config.email); - mailer.send_mail(&format!("Build failed: {}\n{}\n\n{}", msg, code_msg, output)); + mailer.send_mail( + &repo_ptr.name(), + &format!("Build failed: {}\n{}\n\n{}", msg, code_msg, output)); }, ExecutionResult::ExecutionError(msg, output) => { let mailer = mail::build_mailer(&config.email); - mailer.send_mail(&format!("Build failed: {}\n\n{}", msg, output)); + mailer.send_mail( + &repo_ptr.name(), + &format!("Build failed: {}\n\n{}", msg, output)); }, _ => (), } diff --git a/src/mail.rs b/src/mail.rs @@ -6,7 +6,7 @@ use lettre::smtp::ConnectionReuseParameters; use crate::config; pub trait Mailer { - fn send_mail(&self, text: &str); + fn send_mail(&self, name: &str, text: &str); } struct NullMailer; @@ -32,17 +32,17 @@ impl SmtpMailer { } impl Mailer for NullMailer { - fn send_mail(&self, _text: &str) { + fn send_mail(&self, _name: &str, _text: &str) { } } impl Mailer for SmtpMailer { - fn send_mail(&self, text: &str) { + fn send_mail(&self, name: &str, text: &str) { let email = Email::builder() .to(self.to.to_string()) .from(self.from.to_string()) - .subject("Build failed") + .subject(format!("Build failed: {}", name)) .text(text) .build() .unwrap();