2024-09-19 19:12:41 +01:00
|
|
|
//
|
|
|
|
use crate::model::Config;
|
|
|
|
use crate::patterns::{issue_pattern, marker_pattern};
|
2024-09-21 18:25:42 +01:00
|
|
|
use crate::printer::Printer;
|
2024-09-19 19:12:41 +01:00
|
|
|
use anyhow::{Context, Result};
|
2024-09-21 18:25:42 +01:00
|
|
|
use kxio::fs;
|
|
|
|
use kxio::network::Network;
|
2024-09-19 19:12:41 +01:00
|
|
|
|
2024-09-21 18:25:42 +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)
|
2024-09-21 18:25:42 +01:00
|
|
|
.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")?)
|
|
|
|
.prefix_pattern(marker_pattern()?)
|
|
|
|
.issue_pattern(issue_pattern()?)
|
|
|
|
.maybe_auth_token(std::env::var("REPO_TOKEN").ok())
|
|
|
|
.build();
|
|
|
|
|
2024-09-22 09:07:16 +01:00
|
|
|
printer.println("");
|
2024-09-21 18:25:42 +01:00
|
|
|
printer.println(format!("Repo: {}", config.repo()));
|
|
|
|
printer.println(format!("Prefix: {}", config.prefix_pattern()));
|
|
|
|
printer.println(format!("Issues: {}", config.issue_pattern()));
|
2024-09-22 09:07:16 +01:00
|
|
|
printer.println("");
|
2024-09-19 19:12:41 +01:00
|
|
|
|
|
|
|
Ok(config)
|
|
|
|
}
|