From 371541b4c480ba2400cf6b5a3ef380eee9cc48bb Mon Sep 17 00:00:00 2001 From: edef Date: Mon, 20 Jun 2022 09:24:29 +0000 Subject: fleet/pkgs/naut: simplify down to a single channel and a single repo We have a single repository (the monorepo), and a single project channel worth reporting to (Ripple's). Change-Id: I17d84b610639d7eed422d6a7032908d21143a582 --- fleet/hosts/trieste/naut.nix | 6 --- fleet/pkgs/naut/src/main.rs | 99 +++++++------------------------------------- 2 files changed, 15 insertions(+), 90 deletions(-) (limited to 'fleet') diff --git a/fleet/hosts/trieste/naut.nix b/fleet/hosts/trieste/naut.nix index 8b94492..5b219ac 100644 --- a/fleet/hosts/trieste/naut.nix +++ b/fleet/hosts/trieste/naut.nix @@ -6,10 +6,6 @@ let socket = "/run/naut/naut.sock"; proxySocket = "/run/naut-proxy/naut.sock"; - - config = { - "#ripple" = [ "ripple" "ripple-website" ]; - }; in { systemd.sockets.naut-proxy = { wantedBy = [ "sockets.target" ]; @@ -26,7 +22,6 @@ in { wantedBy = [ "multi-user.target" ]; environment.NAUT_SOCK = socket; - environment.NAUT_CONFIG = (pkgs.formats.toml {}).generate "naut.toml" config; serviceConfig = { ExecStart = "${pkgs.naut}/bin/naut"; @@ -42,7 +37,6 @@ in { declarative.git.hooks.post-receive = [ (pkgs.writeShellScript "nautify" '' { - pwd cat } | nc -UN ${proxySocket} '') diff --git a/fleet/pkgs/naut/src/main.rs b/fleet/pkgs/naut/src/main.rs index 39b81b7..6b2550c 100644 --- a/fleet/pkgs/naut/src/main.rs +++ b/fleet/pkgs/naut/src/main.rs @@ -6,13 +6,7 @@ use { git2::{Oid, Repository, Sort}, irc::client::prelude::*, pin_utils::pin_mut, - std::{ - collections::{HashMap, HashSet}, - env, - fs::{remove_file, File}, - io::{ErrorKind, Read}, - path::Path, - }, + std::{env, fs::remove_file, io::ErrorKind}, tokio::{ io::{AsyncBufRead, AsyncBufReadExt, BufReader, Lines}, net::UnixListener, @@ -24,47 +18,11 @@ use { #[derive(Debug)] struct Batch { - repository: String, lines: Vec, } #[tokio::main] async fn main() -> Result<()> { - let repo_by_channel = { - let mut buf = vec![]; - File::open(env::var("NAUT_CONFIG")?)?.read_to_end(&mut buf)?; - let tmp: HashMap> = toml::from_slice(&buf)?; - if tmp.is_empty() { - return Err(anyhow!("No channels configured!")); - } - tmp - }; - - let channels: Vec = repo_by_channel - .keys() - .clone() - .map(ToOwned::to_owned) - .collect(); - - // Invert the config, so we have a map of repositories to channel names - let channel_by_repo = { - let mut tmp = HashMap::new(); - for (channel, repos) in repo_by_channel { - for repo in repos { - tmp.entry(repo) - .or_insert_with(Vec::new) - .push(channel.to_string()); - } - } - tmp - }; - - let repositories: HashSet<_> = channel_by_repo - .keys() - .clone() - .map(ToOwned::to_owned) - .collect(); - let (tx, rx) = mpsc::unbounded_channel::(); let listener = bind(env::var("NAUT_SOCK")?.as_str())?; @@ -73,23 +31,12 @@ async fn main() -> Result<()> { let (stream, _) = listener.accept().await.unwrap(); let tx = tx.clone(); - let repositories = repositories.clone(); let conn = async move { - let mut lines = BufReader::new(stream).lines(); - let path = lines.next_line().await?.unwrap(); + let lines = BufReader::new(stream).lines(); + let repo = Repository::open("/var/lib/git/basin")?; - let repo_name = Path::new(&path).file_name().unwrap().to_str().unwrap(); - if !repositories.contains(repo_name) { - return Err(anyhow!( - "Received a request for an unmanaged repository: {}", - repo_name - )); - } - - let repo = Repository::open(&path)?; - - handle(repo, repo_name, lines, tx).await?; + handle(repo, lines, tx).await?; Ok::<(), Error>(()) }; @@ -101,6 +48,7 @@ async fn main() -> Result<()> { } }); + let channel = "#ripple"; let client_config = Config { server: Some("irc.libera.chat".to_owned()), password: Some(env::var("NAUT_PASS")?), @@ -108,7 +56,7 @@ async fn main() -> Result<()> { realname: Some("blub blub".to_owned()), version: Some(format!("naut {}", env!("CARGO_PKG_VERSION"))), source: Some("https://src.unfathomable.blue/tree/fleet/pkgs/naut".to_owned()), - channels, + channels: vec![channel.to_owned()], ..Default::default() }; @@ -131,11 +79,8 @@ async fn main() -> Result<()> { None => break, }, Some(batch) = rx.next() => { - let channels = channel_by_repo.get(&batch.repository).unwrap(); for line in batch.lines { - for channel in channels { - sender.send_privmsg(channel.to_owned(), line.to_owned())?; - } + sender.send_privmsg("#ripple", line.to_owned())?; } }, } @@ -155,7 +100,6 @@ fn bind(path: &str) -> Result { async fn handle( repo: Repository, - repo_name: &str, mut lines: Lines, tx: UnboundedSender, ) -> Result<()> { @@ -171,17 +115,14 @@ async fn handle( if r#ref.is_branch() { if new.is_zero() { - lines.push(format!( - "[{}] branch {} deleted (was {})", - repo_name, ref_name, old - )); + lines.push(format!("branch {} deleted (was {})", ref_name, old)); } else { let mut walker = repo.revwalk()?; walker.set_sorting(Sort::REVERSE)?; walker.push(new)?; if old.is_zero() { - lines.push(format!("[{}] new branch created: {}", repo_name, ref_name)); + lines.push(format!("new branch created: {}", ref_name)); // We cannot use repo.head directly, as that comes resolved already. let head = repo.find_reference("HEAD")?; @@ -203,8 +144,7 @@ async fn handle( .collect(); lines.push(format!( - "[{}] {} {} pushed to {}", - repo_name, + "{} {} pushed to {}", commits.len(), if commits.len() == 1 { "commit" @@ -225,19 +165,13 @@ async fn handle( } } else if r#ref.is_tag() { if new.is_zero() { - lines.push(format!( - "[{}] tag {} deleted (was {})", - repo_name, ref_name, old - )) + lines.push(format!("tag {} deleted (was {})", ref_name, old)) } else if old.is_zero() { - lines.push(format!( - "[{}] commit {} tagged as {}", - repo_name, new, ref_name - )) + lines.push(format!("commit {} tagged as {}", new, ref_name)) } else { lines.push(format!( - "[{}] tag {} modified (was {}, now {})", - repo_name, ref_name, old, new + "tag {} modified (was {}, now {})", + ref_name, old, new )) } } else { @@ -247,10 +181,7 @@ async fn handle( )); } - tx.send(Batch { - repository: repo_name.to_owned(), - lines, - })?; + tx.send(Batch { lines })?; } Ok(()) -- cgit 1.4.1