forgejo-todo-checker/src/init.rs

30 lines
922 B
Rust
Raw Normal View History

2024-09-19 19:12:41 +01:00
//
use crate::model::Config;
use crate::patterns::issue_pattern;
use crate::printer::Printer;
2024-09-19 19:12:41 +01:00
use anyhow::{Context, Result};
use kxio::fs;
use kxio::network::Network;
2024-09-19 19:12:41 +01:00
pub fn init_config(printer: &impl Printer, net: Network) -> Result<Config> {
2024-09-19 19:12:41 +01:00
let config = Config::builder()
2024-09-20 07:23:36 +01:00
.net(net)
.fs(fs::new(
2024-09-19 19:12:41 +01:00
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")?)
.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)
}