forgejo-todo-checker/src/init.rs
Paul Campbell b50f73b7b7
All checks were successful
Test / build (map[name:stable]) (push) Successful in 5m51s
Test / build (map[name:nightly]) (push) Successful in 5m2s
feat: add cli args to help run locally
2025-01-05 09:05:11 +00:00

46 lines
1.7 KiB
Rust

//
use crate::patterns::issue_pattern;
use crate::printer::Printer;
use crate::{model::Config, Args};
use color_eyre::eyre::ContextCompat as _;
use color_eyre::Section;
use color_eyre::{eyre::Context, Result};
use kxio::{fs::FileSystem, net::Net};
pub fn init_config<'net, 'fs>(
printer: &impl Printer,
fs: &'fs FileSystem,
net: &'net Net,
args: &Args,
) -> Result<Config<'net, 'fs>> {
let config = Config::builder()
.net(net)
.fs(fs)
.repo(
std::env::var("GITHUB_REPOSITORY")
.or_else(|_| {
args.repo
.as_ref()
.map(|repo| repo.to_string())
.context("--repo <OWNER>/<REPO> not provided")
})
.context("GITHUB_REPOSITORY environment not defined")
.suggestion("Try adding '--repo <OWNER>/<REPO>' if running from the command line.")?,
)
.server(
std::env::var("GITHUB_SERVER_URL")
.or_else(|_| args.site.as_ref().map(|url| url.to_string()).context("--site <URL> not provided"))
.context("GITHUB_SERVER_URL environment not defined")
.suggestion("Try adding '--site https://<FORGEJO_HOSTNAME>' if running from the command line. Use the URL of the Forgejo instance where the issues are held.")?,
)
.issue_pattern(issue_pattern()?)
.maybe_auth_token(std::env::var("REPO_TOKEN").ok())
.build();
printer.println("");
printer.println(format!("Repo : {}", config.repo()));
printer.println(format!("Regex: {}", config.issue_pattern()));
printer.println("");
Ok(config)
}