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]
# Testing
# assert2 = "0.3"
assert2 = "0.3"
test-log = "0.2"
anyhow = "1.0"

View file

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

View file

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