From f1d7d71471495f1f0a62cfe0da71ee856f68acd3 Mon Sep 17 00:00:00 2001 From: Jason Liquorish Date: Sun, 7 Oct 2018 17:06:29 +0100 Subject: [PATCH] Add test bot for CI --- .travis.yml | 1 + src/bin/build-bot.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/bin/build-bot.rs diff --git a/.travis.yml b/.travis.yml index a7e0d6a..d444f95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ script: - cargo test --verbose --features "toml yaml" - cargo test --doc - cargo test --verbose --no-default-features + - cargo run --bin build-bot notifications: email: false irc: diff --git a/src/bin/build-bot.rs b/src/bin/build-bot.rs new file mode 100644 index 0000000..3d87b8b --- /dev/null +++ b/src/bin/build-bot.rs @@ -0,0 +1,43 @@ +extern crate irc; + +use irc::client::prelude::*; +use std::default::Default; +use std::env; + +fn main() { + let repository_slug = env::var("TRAVIS_REPO_SLUG").unwrap(); + let branch = env::var("TRAVIS_BRANCH").unwrap(); + let commit = env::var("TRAVIS_COMMIT").unwrap(); + let commit_message = env::var("TRAVIS_COMMIT_MESSAGE").unwrap(); + + let config = Config { + nickname: Some("irc-crate-ci".to_owned()), + server: Some("irc.pdgn.co".to_owned()), + use_ssl: Some(true), + ..Default::default() + }; + + let mut reactor = IrcReactor::new().unwrap(); + let client = reactor.prepare_client_and_connect(&config).unwrap(); + client.identify().unwrap(); + + reactor.register_client_with_handler(client, move |client, message| { + match message.command { + Command::Response(Response::RPL_ISUPPORT, _, _) => { + client.send_privmsg( + "#commits", + format!( + "Hello from Travis CI! {}/{} {}: {}", + repository_slug, branch, commit, commit_message + ), + )?; + client.send_quit("QUIT")?; + } + _ => (), + }; + + Ok(()) + }); + + reactor.run().unwrap(); +}