summary refs log tree commit diff
path: root/fleet/pkgs
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-06-20 09:24:29 +0000
committeredef <edef@unfathomable.blue>2022-06-20 11:00:00 +0000
commit371541b4c480ba2400cf6b5a3ef380eee9cc48bb (patch)
treedfa0f857f34b6adbf8db35bbaee5b10e5f13675e /fleet/pkgs
parentbc967bb90e50bf151de7e9c91a6111e4b1d8746a (diff)
downloadunf-legacy-371541b4c480ba2400cf6b5a3ef380eee9cc48bb.tar.zst
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
Diffstat (limited to 'fleet/pkgs')
-rw-r--r--fleet/pkgs/naut/src/main.rs99
1 files changed, 15 insertions, 84 deletions
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<String>,
 }
 
 #[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<String, Vec<String>> = toml::from_slice(&buf)?;
-		if tmp.is_empty() {
-			return Err(anyhow!("No channels configured!"));
-		}
-		tmp
-	};
-
-	let channels: Vec<String> = 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::<Batch>();
 
 	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<UnixListener> {
 
 async fn handle(
 	repo: Repository,
-	repo_name: &str,
 	mut lines: Lines<impl AsyncBufRead + Unpin>,
 	tx: UnboundedSender<Batch>,
 ) -> 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(())