// 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> { 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 / not provided") }) .context("GITHUB_REPOSITORY environment not defined") .suggestion("Try adding '--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 not provided")) .context("GITHUB_SERVER_URL environment not defined") .suggestion("Try adding '--site https://' 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) }