git-next/crates/config/src/forge_config.rs
Paul Campbell ffab1986a7
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
Rust / build (push) Has been cancelled
ci/woodpecker/push/tag-created Pipeline was successful
refactor: repo-actor: rewrite tests using mockall
2024-06-27 18:58:47 +01:00

53 lines
1.2 KiB
Rust

use std::collections::BTreeMap;
use crate::{ApiToken, ForgeType, Hostname, RepoAlias, ServerRepoConfig, User};
/// Defines a Forge to connect to
/// Maps from `git-next-server.toml` at `forge.{forge}`
#[derive(
Clone,
Debug,
derive_more::From,
PartialEq,
Eq,
PartialOrd,
Ord,
serde::Deserialize,
derive_more::Constructor,
derive_more::Display,
)]
#[display("{}:{}@{}", forge_type.to_string().to_lowercase(), user, hostname)]
pub struct ForgeConfig {
forge_type: ForgeType,
hostname: String,
user: String,
token: String,
repos: BTreeMap<String, ServerRepoConfig>,
}
impl ForgeConfig {
pub const fn forge_type(&self) -> ForgeType {
self.forge_type
}
pub fn hostname(&self) -> Hostname {
Hostname::new(&self.hostname)
}
pub fn user(&self) -> User {
User::new(self.user.clone())
}
pub fn token(&self) -> ApiToken {
ApiToken::new(self.token.clone().into())
}
pub fn repos(&self) -> impl Iterator<Item = (RepoAlias, &ServerRepoConfig)> {
self.repos
.iter()
.map(|(name, repo)| (RepoAlias::new(name), repo))
}
pub fn get_repo(&self, arg: &str) -> Option<&ServerRepoConfig> {
self.repos.get(arg)
}
}