forgejo-todo-checker/src/init.rs

47 lines
1.7 KiB
Rust
Raw Normal View History

2024-09-19 19:12:41 +01:00
//
use crate::patterns::issue_pattern;
use crate::printer::Printer;
2025-01-04 20:46:01 +00:00
use crate::{model::Config, Args};
use color_eyre::eyre::ContextCompat as _;
use color_eyre::Section;
2024-12-03 07:41:51 +00:00
use color_eyre::{eyre::Context, Result};
use kxio::{fs::FileSystem, net::Net};
2024-09-19 19:12:41 +01:00
pub fn init_config<'net, 'fs>(
printer: &impl Printer,
fs: &'fs FileSystem,
net: &'net Net,
2025-01-04 20:46:01 +00:00
args: &Args,
) -> Result<Config<'net, 'fs>> {
2024-09-19 19:12:41 +01:00
let config = Config::builder()
2024-09-20 07:23:36 +01:00
.net(net)
.fs(fs)
2025-01-04 20:46:01 +00:00
.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.")?,
)
2024-09-19 19:12:41 +01:00
.issue_pattern(issue_pattern()?)
.maybe_auth_token(std::env::var("REPO_TOKEN").ok())
.build();
2024-09-22 09:07:16 +01:00
printer.println("");
printer.println(format!("Repo : {}", config.repo()));
printer.println(format!("Regex: {}", config.issue_pattern()));
2024-09-22 09:07:16 +01:00
printer.println("");
2024-09-19 19:12:41 +01:00
Ok(config)
}