forked from kemitix/git-next
refactor(server/config): rename RepoConfigValidationError as Error
It is never referenced directly outside of this module.
This commit is contained in:
parent
eb7d14bc33
commit
f8375ed1fc
1 changed files with 7 additions and 24 deletions
|
@ -8,15 +8,7 @@ use crate::gitforge::{self, ForgeFileError};
|
||||||
pub async fn load(
|
pub async fn load(
|
||||||
details: &RepoDetails,
|
details: &RepoDetails,
|
||||||
forge: &gitforge::Forge,
|
forge: &gitforge::Forge,
|
||||||
) -> Result<
|
) -> Result<RepoConfig, OneOf<(ForgeFileError, crate::config::Error, toml::de::Error, Error)>> {
|
||||||
RepoConfig,
|
|
||||||
OneOf<(
|
|
||||||
ForgeFileError,
|
|
||||||
crate::config::Error,
|
|
||||||
toml::de::Error,
|
|
||||||
RepoConfigValidationErrors,
|
|
||||||
)>,
|
|
||||||
> {
|
|
||||||
let contents = forge
|
let contents = forge
|
||||||
.file_contents_get(&details.branch, ".git-next.toml")
|
.file_contents_get(&details.branch, ".git-next.toml")
|
||||||
.await
|
.await
|
||||||
|
@ -27,42 +19,33 @@ pub async fn load(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RepoConfigValidationErrors {
|
pub enum Error {
|
||||||
Forge(gitforge::ForgeBranchError),
|
Forge(gitforge::ForgeBranchError),
|
||||||
BranchNotFound(BranchName),
|
BranchNotFound(BranchName),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn validate(
|
pub async fn validate(config: RepoConfig, forge: &gitforge::Forge) -> Result<RepoConfig, Error> {
|
||||||
config: RepoConfig,
|
|
||||||
forge: &gitforge::Forge,
|
|
||||||
) -> Result<RepoConfig, RepoConfigValidationErrors> {
|
|
||||||
let branches = forge.branches_get_all().await.map_err(|e| {
|
let branches = forge.branches_get_all().await.map_err(|e| {
|
||||||
error!(?e, "Failed to list branches");
|
error!(?e, "Failed to list branches");
|
||||||
RepoConfigValidationErrors::Forge(e)
|
Error::Forge(e)
|
||||||
})?;
|
})?;
|
||||||
if !branches
|
if !branches
|
||||||
.iter()
|
.iter()
|
||||||
.any(|branch| branch == &config.branches().main())
|
.any(|branch| branch == &config.branches().main())
|
||||||
{
|
{
|
||||||
return Err(RepoConfigValidationErrors::BranchNotFound(
|
return Err(Error::BranchNotFound(config.branches().main()));
|
||||||
config.branches().main(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
if !branches
|
if !branches
|
||||||
.iter()
|
.iter()
|
||||||
.any(|branch| branch == &config.branches().next())
|
.any(|branch| branch == &config.branches().next())
|
||||||
{
|
{
|
||||||
return Err(RepoConfigValidationErrors::BranchNotFound(
|
return Err(Error::BranchNotFound(config.branches().next()));
|
||||||
config.branches().next(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
if !branches
|
if !branches
|
||||||
.iter()
|
.iter()
|
||||||
.any(|branch| branch == &config.branches().dev())
|
.any(|branch| branch == &config.branches().dev())
|
||||||
{
|
{
|
||||||
return Err(RepoConfigValidationErrors::BranchNotFound(
|
return Err(Error::BranchNotFound(config.branches().dev()));
|
||||||
config.branches().dev(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue