use git_next_config::{self as config, BranchName, RepoConfig}; use git_next_forge as forge; use git_next_git::RepoDetails; use tracing::error; pub async fn load(details: &RepoDetails, forge: &forge::Forge) -> Result { let contents = forge .file_contents_get(&details.branch, ".git-next.toml") .await?; let config = RepoConfig::load(&contents)?; let config = validate(config, forge).await?; Ok(config) } #[derive(Debug, derive_more::From, derive_more::Display)] pub enum Error { File(forge::file::Error), Config(config::server::Error), Toml(toml::de::Error), Forge(forge::branch::Error), BranchNotFound(BranchName), } pub async fn validate(config: RepoConfig, forge: &forge::Forge) -> Result { let branches = forge.branches_get_all().await.map_err(|e| { error!(?e, "Failed to list branches"); Error::Forge(e) })?; if !branches .iter() .any(|branch| branch == &config.branches().main()) { return Err(Error::BranchNotFound(config.branches().main())); } if !branches .iter() .any(|branch| branch == &config.branches().next()) { return Err(Error::BranchNotFound(config.branches().next())); } if !branches .iter() .any(|branch| branch == &config.branches().dev()) { return Err(Error::BranchNotFound(config.branches().dev())); } Ok(config) }