forgejo-todo-checker/src/main.rs

63 lines
2.2 KiB
Rust
Raw Normal View History

use std::path::PathBuf;
2024-09-17 18:03:50 +01:00
use anyhow::Context;
use regex::Regex;
struct Config {
workdir: PathBuf,
repo: String,
server: String,
auth_token: Option<String>,
prefix_pattern: Regex,
issue_pattern: Regex,
}
2024-09-17 18:03:50 +01:00
fn main() -> anyhow::Result<()> {
println!("Forgejo TODO Checker!");
let config = Config {
workdir: std::env::var("GITHUB_WORKSPACE")
.context("GITHUB_WORKSPACE")?
.into(),
repo: std::env::var("GITHUB_REPOSITORY").context("GITHUB_REPOSITORY")?,
server: std::env::var("GITHUB_SERVER_URL").context("GITHUB_SERVER_URL")?,
auth_token: std::env::var("REPO_TOKEN").ok(),
prefix_pattern: regex::Regex::new(r"(#|//)\s*(TODO|FIXME)").context("prefix regex")?,
issue_pattern: regex::Regex::new(r"( |)(\(|\(#)(?P<ISSUE_NUMBER>\d+)(\))")
.context("issue regex")?,
};
2024-09-17 18:03:50 +01:00
println!("Repo: {}", config.repo);
println!("Prefix: {}", config.prefix_pattern);
println!("Issues: {}", config.issue_pattern);
2024-09-17 18:03:50 +01:00
// TODO: scan files in workdir
// TODO: ignore files listed in .rgignore .ignore or .gitignore
// TODO: scan for malformed TODO and FIXME comments (e.g. no issue number) - add to error list
// TODO: build list of expected open issues with file locations where found
2024-09-17 18:03:50 +01:00
// list files in current directory to get a feel for what we have access to
// std::fs::read_dir(workdir)?
// .filter_map(Result::ok)
// .map(|e| e.path())
// .for_each(|e| println!("{e:?}"));
// Collect open issues:
// let limit = 10;
// let page = 0;
// let api = format!(
// "{ci_server_url}/api/v1/repos/{ci_repo}/issues?state=open&limit=${limit}&page=${page}"
// );
// TODO: add authentication when provided
// let issues = ureq::get(&api).call()?.into_string()?;
// TODO: parse issues to get list of open issue numbers
// TODO: loop over list of expected issues and drop any where they do exist and are open
// TODO: if remaining list is not empty - add all to error list
//
// TODO: if error list is empty - exit okay
// TODO: if error list is not empty - log erros and exit not okay
Ok(())
}