Compare commits

..

No commits in common. "a1484939ab9b0c76a5df9a000318ae2ecca94f72" and "abbd2e66e6c8143cdeac4e5094f6f0e6a4ebce5a" have entirely different histories.

3 changed files with 26 additions and 50 deletions

View file

@ -30,7 +30,7 @@ actix-rt = "2.9"
[dev-dependencies] [dev-dependencies]
# Testing # Testing
# assert2 = "0.3" assert2 = "0.3"
test-log = "0.2" test-log = "0.2"
anyhow = "1.0" anyhow = "1.0"

View file

@ -2,7 +2,7 @@
forge_type = "ForgeJo" forge_type = "ForgeJo"
hostname = "git.example.net" hostname = "git.example.net"
user = "git-next" # the user to perform actions as user = "git-next" # the user to perform actions as
token = "API-Token" # API token for user?
# path to private SSH key for user? # path to private SSH key for user?
[forge.default.repos] [forge.default.repos]

View file

@ -47,7 +47,6 @@ pub struct Forge {
forge_type: ForgeType, forge_type: ForgeType,
hostname: String, hostname: String,
user: String, user: String,
token: String,
// API Token // API Token
// Private SSH Key Path // Private SSH Key Path
repos: HashMap<String, Repo>, repos: HashMap<String, Repo>,
@ -65,10 +64,6 @@ impl Forge {
User(self.user.clone()) User(self.user.clone())
} }
pub fn token(&self) -> ApiToken {
ApiToken(self.token.clone())
}
pub fn repos(&self) -> impl Iterator<Item = (RepoName, &Repo)> { pub fn repos(&self) -> impl Iterator<Item = (RepoName, &Repo)> {
self.repos self.repos
.iter() .iter()
@ -82,6 +77,13 @@ pub struct Repo {
branch: String, branch: String,
} }
impl Repo { impl Repo {
#[cfg(test)]
pub fn new(repo: &str, branch: &str) -> Self {
Self {
repo: repo.to_string(),
branch: branch.to_string(),
}
}
#[allow(dead_code)] #[allow(dead_code)]
pub fn repo(&self) -> RepoPath { pub fn repo(&self) -> RepoPath {
RepoPath(self.repo.clone()) RepoPath(self.repo.clone())
@ -125,19 +127,11 @@ impl Display for User {
} }
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct ApiToken(pub String);
impl Display for ApiToken {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ForgeDetails { pub struct ForgeDetails {
pub name: ForgeName, pub name: ForgeName,
pub forge_type: ForgeType, pub forge_type: ForgeType,
pub hostname: Hostname, pub hostname: Hostname,
pub user: User, pub user: User,
pub token: ApiToken,
// API Token // API Token
// Private SSH Key Path // Private SSH Key Path
} }
@ -146,9 +140,8 @@ impl From<(&ForgeName, &Forge)> for ForgeDetails {
Self { Self {
name: forge.0.clone(), name: forge.0.clone(),
forge_type: forge.1.forge_type.clone(), forge_type: forge.1.forge_type.clone(),
hostname: forge.1.hostname(), hostname: Hostname(forge.1.hostname.clone()),
user: forge.1.user(), user: User(forge.1.user.clone()),
token: forge.1.token(),
} }
} }
} }
@ -189,9 +182,8 @@ impl RepoDetails {
forge: ForgeDetails { forge: ForgeDetails {
name: forge_name.clone(), name: forge_name.clone(),
forge_type: forge.forge_type.clone(), forge_type: forge.forge_type.clone(),
hostname: forge.hostname(), hostname: Hostname(forge.hostname.clone()),
user: forge.user(), user: User(forge.user.clone()),
token: forge.token(),
}, },
} }
} }
@ -228,6 +220,7 @@ impl Display for ForgeType {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use assert2::let_assert;
use crate::filesystem::FileSystem; use crate::filesystem::FileSystem;
@ -243,7 +236,6 @@ mod tests {
forge_type = "ForgeJo" forge_type = "ForgeJo"
hostname = "git.example.net" hostname = "git.example.net"
user = "Bob" user = "Bob"
token = "API-Token"
[forge.default.repos] [forge.default.repos]
hello = { repo = "user/hello", branch = "main" } hello = { repo = "user/hello", branch = "main" }
@ -252,34 +244,18 @@ mod tests {
) )
.map_err(OneOf::new)?; .map_err(OneOf::new)?;
let config = ServerConfig::load(&fs)?; let config = ServerConfig::load(&fs)?;
let expected = ServerConfig { let_assert!(Some(default) = config.forge.get("default"));
forge: HashMap::from([( assert_eq!(default.forge_type, ForgeType::ForgeJo);
"default".to_string(), assert_eq!(default.hostname, "git.example.net".to_string());
Forge { assert_eq!(default.user, "Bob".to_string());
forge_type: ForgeType::ForgeJo, assert_eq!(
hostname: "git.example.net".to_string(), default.repos.get("hello"),
user: "Bob".to_string(), Some(Repo::new("user/hello", "main").as_ref())
token: "API-Token".to_string(), );
repos: HashMap::from([ assert_eq!(
( default.repos.get("world"),
"hello".to_string(), Some(Repo::new("user/world", "master").as_ref())
Repo { );
repo: "user/hello".to_string(),
branch: "main".to_string(),
},
),
(
"world".to_string(),
Repo {
repo: "user/world".to_string(),
branch: "master".to_string(),
},
),
]),
},
)]),
};
assert_eq!(config, expected);
Ok(()) Ok(())
} }