From 57f88bb832f22956baaf7a04f3489679c75e7696 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 20 Sep 2024 15:49:17 +0100 Subject: [PATCH] feat: log any invalid/closed markers and exit if any found --- src/main.rs | 20 ++++++++++++++------ src/model/markers/mod.rs | 9 +++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 81668de..088743a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ // -use anyhow::Result; +use anyhow::{bail, Result}; use init::init_config; use issues::fetch_open_issues; use scanner::find_markers; @@ -22,14 +22,22 @@ async fn run(net: kxio::network::Network) -> Result<()> { println!("Forgejo TODO Checker!"); let config = init_config(net)?; - let issues = fetch_open_issues(&config).await?; - let markers = find_markers(&config, issues)?; - println!("{markers}"); - // TODO: loop over markers, logging any that are invalid or closed. - // TODO: if we logged any, then exit as and error + let mut errors = false; + for marker in (*markers).iter() { + match marker { + model::Marker::Closed(_, _) | model::Marker::Invalid(_) => { + println!("{marker}"); + errors = true; + } + model::Marker::Unmarked | model::Marker::Valid(_, _) => {} + } + } + if errors { + bail!("Invalid or closed TODO/FIXMEs found") + } Ok(()) } diff --git a/src/model/markers/mod.rs b/src/model/markers/mod.rs index 24d7de6..e392629 100644 --- a/src/model/markers/mod.rs +++ b/src/model/markers/mod.rs @@ -3,6 +3,8 @@ #[cfg(test)] mod tests; +use std::ops::Deref; + use crate::{issues::Issue, model::Line}; #[derive(Debug)] @@ -42,6 +44,13 @@ impl Markers { self.markers.push(marker); } } +impl Deref for Markers { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.markers + } +} impl std::fmt::Display for Markers { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for marker in self.markers.iter() {