2024-05-11 19:46:20 +01:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use crate::{ApiToken, ForgeType, Hostname, RepoAlias, ServerRepoConfig, User};
|
|
|
|
|
|
|
|
/// Defines a Forge to connect to
|
|
|
|
/// Maps from `git-next-server.toml` at `forge.{forge}`
|
2024-05-12 22:27:20 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::Display)]
|
|
|
|
#[display("{}:{}@{}", forge_type.to_string().to_lowercase(), user, hostname)]
|
2024-05-11 19:46:20 +01:00
|
|
|
pub struct ForgeConfig {
|
|
|
|
pub forge_type: ForgeType,
|
|
|
|
pub hostname: String,
|
|
|
|
pub user: String,
|
|
|
|
pub token: String,
|
|
|
|
pub repos: HashMap<String, ServerRepoConfig>,
|
|
|
|
}
|
|
|
|
impl ForgeConfig {
|
2024-05-12 22:27:20 +01:00
|
|
|
pub const fn forge_type(&self) -> ForgeType {
|
|
|
|
self.forge_type
|
2024-05-11 19:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn hostname(&self) -> Hostname {
|
|
|
|
Hostname(self.hostname.clone())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn user(&self) -> User {
|
|
|
|
User(self.user.clone())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn token(&self) -> ApiToken {
|
|
|
|
ApiToken(self.token.clone().into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn repos(&self) -> impl Iterator<Item = (RepoAlias, &ServerRepoConfig)> {
|
|
|
|
self.repos
|
|
|
|
.iter()
|
|
|
|
.map(|(name, repo)| (RepoAlias(name.clone()), repo))
|
|
|
|
}
|
|
|
|
}
|