83 lines
2 KiB
Rust
83 lines
2 KiB
Rust
use std::path::PathBuf;
|
|
|
|
//
|
|
use color_eyre::{
|
|
eyre::{bail, Context as _},
|
|
Result,
|
|
};
|
|
use init::init_config;
|
|
use issues::fetch_open_issues;
|
|
use printer::{Printer, StandardPrinter};
|
|
use scanner::{find_markers, DefaultFileScanner};
|
|
|
|
mod init;
|
|
mod issues;
|
|
mod model;
|
|
mod patterns;
|
|
mod printer;
|
|
mod scanner;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
#[derive(clap::Parser, Default)]
|
|
struct Args {
|
|
/// Root directory of the project to be scanned.
|
|
#[clap(long)]
|
|
workspace: Option<PathBuf>,
|
|
|
|
/// Forgejo site URL (e.g. https://git.kemitix.net)
|
|
#[clap(long)]
|
|
site: Option<String>,
|
|
|
|
/// Repo owner and name (e.g. kemitix/forgejo-todo-checker)
|
|
#[clap(long)]
|
|
repo: Option<String>,
|
|
}
|
|
|
|
#[tokio::main]
|
|
#[cfg(not(tarpaulin_include))]
|
|
#[cfg_attr(test, mutants::skip)]
|
|
async fn main() -> Result<()> {
|
|
use clap::Parser;
|
|
use color_eyre::{eyre::ContextCompat as _, Section};
|
|
|
|
color_eyre::install()?;
|
|
let args = Args::parse();
|
|
let github_workspace = std::env::var("GITHUB_WORKSPACE")
|
|
.or_else(|_| {
|
|
args.workspace.as_ref()
|
|
.map(|cd| cd.display().to_string())
|
|
.context("--workspace $PWD not provided")
|
|
})
|
|
.context("GITHUB_WORKSPACE environment not defined")
|
|
.suggestion("Try adding '--workspace $PWD' if running from the command line. N.B. The path MUST be absolute.")?;
|
|
let fs = kxio::fs::new(github_workspace);
|
|
|
|
let net = kxio::net::new();
|
|
|
|
let printer = &StandardPrinter;
|
|
|
|
run(printer, &fs, &net, &args).await?;
|
|
|
|
printer.println("Okay - no problems found");
|
|
Ok(())
|
|
}
|
|
|
|
async fn run(
|
|
printer: &impl Printer,
|
|
fs: &kxio::fs::FileSystem,
|
|
net: &kxio::net::Net,
|
|
args: &Args,
|
|
) -> Result<()> {
|
|
printer.println("Forgejo TODO Checker!");
|
|
|
|
let config = init_config(printer, fs, net, args)?;
|
|
let issues = fetch_open_issues(&config).await?;
|
|
let errors = find_markers(printer, &config, issues, &DefaultFileScanner)?;
|
|
|
|
if errors > 0 {
|
|
bail!("Invalid or closed TODO/FIXMEs found")
|
|
}
|
|
Ok(())
|
|
}
|