Compare commits
4 commits
abbd2e66e6
...
a1484939ab
Author | SHA1 | Date | |
---|---|---|---|
a1484939ab | |||
aaaa975911 | |||
be01d106a4 | |||
3c4a0d52b1 |
3 changed files with 50 additions and 26 deletions
|
@ -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"
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
# API token for user?
|
token = "API-Token"
|
||||||
# path to private SSH key for user?
|
# path to private SSH key for user?
|
||||||
|
|
||||||
[forge.default.repos]
|
[forge.default.repos]
|
||||||
|
|
|
@ -47,6 +47,7 @@ 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>,
|
||||||
|
@ -64,6 +65,10 @@ 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()
|
||||||
|
@ -77,13 +82,6 @@ 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())
|
||||||
|
@ -127,11 +125,19 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -140,8 +146,9 @@ 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: Hostname(forge.1.hostname.clone()),
|
hostname: forge.1.hostname(),
|
||||||
user: User(forge.1.user.clone()),
|
user: forge.1.user(),
|
||||||
|
token: forge.1.token(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,8 +189,9 @@ 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: Hostname(forge.hostname.clone()),
|
hostname: forge.hostname(),
|
||||||
user: User(forge.user.clone()),
|
user: forge.user(),
|
||||||
|
token: forge.token(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,7 +228,6 @@ impl Display for ForgeType {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert2::let_assert;
|
|
||||||
|
|
||||||
use crate::filesystem::FileSystem;
|
use crate::filesystem::FileSystem;
|
||||||
|
|
||||||
|
@ -236,6 +243,7 @@ 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" }
|
||||||
|
@ -244,18 +252,34 @@ mod tests {
|
||||||
)
|
)
|
||||||
.map_err(OneOf::new)?;
|
.map_err(OneOf::new)?;
|
||||||
let config = ServerConfig::load(&fs)?;
|
let config = ServerConfig::load(&fs)?;
|
||||||
let_assert!(Some(default) = config.forge.get("default"));
|
let expected = ServerConfig {
|
||||||
assert_eq!(default.forge_type, ForgeType::ForgeJo);
|
forge: HashMap::from([(
|
||||||
assert_eq!(default.hostname, "git.example.net".to_string());
|
"default".to_string(),
|
||||||
assert_eq!(default.user, "Bob".to_string());
|
Forge {
|
||||||
assert_eq!(
|
forge_type: ForgeType::ForgeJo,
|
||||||
default.repos.get("hello"),
|
hostname: "git.example.net".to_string(),
|
||||||
Some(Repo::new("user/hello", "main").as_ref())
|
user: "Bob".to_string(),
|
||||||
);
|
token: "API-Token".to_string(),
|
||||||
assert_eq!(
|
repos: HashMap::from([
|
||||||
default.repos.get("world"),
|
(
|
||||||
Some(Repo::new("user/world", "master").as_ref())
|
"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);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue