forgejo-todo-checker/src/main.rs
Paul Campbell 5077452f20
All checks were successful
Test / test (push) Successful in 10s
refactor: abstract printer via Printer trait
2024-09-21 18:26:18 +01:00

49 lines
1.2 KiB
Rust

//
use anyhow::{bail, Result};
use init::init_config;
use issues::fetch_open_issues;
use kxio::network::Network;
use printer::Printer;
use scanner::{find_markers, DefaultFileScanner};
mod init;
mod issues;
mod model;
mod patterns;
mod printer;
mod scanner;
#[cfg(test)]
mod tests;
#[tokio::main]
#[cfg(not(tarpaulin_include))]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
use printer::StandardPrinter;
Ok(run(&StandardPrinter, Network::new_real()).await?)
}
async fn run(printer: &impl Printer, net: Network) -> Result<()> {
printer.println("Forgejo TODO Checker!");
let config = init_config(printer, net)?;
let issues = fetch_open_issues(&config).await?;
let markers = find_markers(&config, issues, &DefaultFileScanner)?;
let mut errors = false;
for marker in (*markers).iter() {
match marker {
model::Marker::Closed(_, _) | model::Marker::Invalid(_) => {
printer.println("{marker}");
errors = true;
}
model::Marker::Unmarked | model::Marker::Valid(_, _) => {}
}
}
if errors {
bail!("Invalid or closed TODO/FIXMEs found")
}
Ok(())
}