2025-01-04 20:46:01 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2024-09-18 11:55:33 +01:00
|
|
|
//
|
2024-12-03 07:41:51 +00:00
|
|
|
use color_eyre::{
|
|
|
|
eyre::{bail, Context as _},
|
|
|
|
Result,
|
|
|
|
};
|
2024-09-19 19:12:41 +01:00
|
|
|
use init::init_config;
|
2024-09-20 07:23:36 +01:00
|
|
|
use issues::fetch_open_issues;
|
2024-11-14 20:15:36 +00:00
|
|
|
use printer::{Printer, StandardPrinter};
|
2024-09-21 11:35:56 +01:00
|
|
|
use scanner::{find_markers, DefaultFileScanner};
|
2024-09-18 11:55:33 +01:00
|
|
|
|
2024-09-19 19:12:41 +01:00
|
|
|
mod init;
|
2024-09-20 07:23:36 +01:00
|
|
|
mod issues;
|
2024-09-18 11:55:33 +01:00
|
|
|
mod model;
|
2024-09-18 15:28:17 +01:00
|
|
|
mod patterns;
|
2024-09-21 18:25:42 +01:00
|
|
|
mod printer;
|
2024-09-19 19:12:41 +01:00
|
|
|
mod scanner;
|
2024-09-17 19:42:05 +01:00
|
|
|
|
2024-09-19 19:32:15 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2025-01-04 20:46:01 +00:00
|
|
|
#[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>,
|
|
|
|
}
|
|
|
|
|
2024-09-20 07:23:36 +01:00
|
|
|
#[tokio::main]
|
2024-09-21 11:35:56 +01:00
|
|
|
#[cfg(not(tarpaulin_include))]
|
2024-11-28 17:31:08 +00:00
|
|
|
#[cfg_attr(test, mutants::skip)]
|
2024-12-03 07:41:51 +00:00
|
|
|
async fn main() -> Result<()> {
|
2025-01-04 20:46:01 +00:00
|
|
|
use clap::Parser;
|
|
|
|
use color_eyre::{eyre::ContextCompat as _, Section};
|
|
|
|
|
2024-12-03 07:41:51 +00:00
|
|
|
color_eyre::install()?;
|
2025-01-04 20:46:01 +00:00
|
|
|
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.")?;
|
2024-11-14 20:15:36 +00:00
|
|
|
let fs = kxio::fs::new(github_workspace);
|
2024-09-21 18:25:42 +01:00
|
|
|
|
2024-11-14 20:15:36 +00:00
|
|
|
let net = kxio::net::new();
|
|
|
|
|
2025-01-04 20:46:01 +00:00
|
|
|
let printer = &StandardPrinter;
|
|
|
|
|
|
|
|
run(printer, &fs, &net, &args).await?;
|
|
|
|
|
|
|
|
printer.println("Okay - no problems found");
|
|
|
|
Ok(())
|
2024-09-19 20:37:23 +01:00
|
|
|
}
|
|
|
|
|
2024-11-14 20:15:36 +00:00
|
|
|
async fn run(
|
|
|
|
printer: &impl Printer,
|
|
|
|
fs: &kxio::fs::FileSystem,
|
|
|
|
net: &kxio::net::Net,
|
2025-01-04 20:46:01 +00:00
|
|
|
args: &Args,
|
2024-11-14 20:15:36 +00:00
|
|
|
) -> Result<()> {
|
2024-09-21 18:25:42 +01:00
|
|
|
printer.println("Forgejo TODO Checker!");
|
2024-09-17 16:48:09 +01:00
|
|
|
|
2025-01-04 20:46:01 +00:00
|
|
|
let config = init_config(printer, fs, net, args)?;
|
2024-09-20 14:36:01 +01:00
|
|
|
let issues = fetch_open_issues(&config).await?;
|
2024-09-21 18:44:40 +01:00
|
|
|
let errors = find_markers(printer, &config, issues, &DefaultFileScanner)?;
|
2024-09-17 16:48:09 +01:00
|
|
|
|
2024-09-21 18:44:40 +01:00
|
|
|
if errors > 0 {
|
2024-09-20 15:49:17 +01:00
|
|
|
bail!("Invalid or closed TODO/FIXMEs found")
|
|
|
|
}
|
2024-09-17 16:48:09 +01:00
|
|
|
Ok(())
|
2024-09-17 16:26:32 +01:00
|
|
|
}
|