2024-05-11 19:46:20 +01:00
|
|
|
use git_next_config::{
|
2024-05-29 19:22:05 +01:00
|
|
|
BranchName, ForgeAlias, ForgeConfig, ForgeDetails, GitDir, RepoAlias, RepoConfig, RepoPath,
|
2024-05-11 19:46:20 +01:00
|
|
|
ServerRepoConfig,
|
|
|
|
};
|
|
|
|
|
|
|
|
use super::{Generation, GitRemote};
|
|
|
|
|
|
|
|
/// The derived information about a repo, used to interact with it
|
2024-05-19 20:02:06 +01:00
|
|
|
#[derive(Clone, Default, Debug, derive_more::Display, derive_with::With)]
|
2024-05-15 07:55:05 +01:00
|
|
|
#[display("gen-{}:{}:{}/{}:{}@{}/{}@{}", generation, forge.forge_type(),
|
2024-05-29 19:22:05 +01:00
|
|
|
forge.forge_alias(), repo_alias, forge.user(), forge.hostname(), repo_path,
|
2024-05-14 16:28:17 +01:00
|
|
|
branch)]
|
2024-05-11 19:46:20 +01:00
|
|
|
pub struct RepoDetails {
|
|
|
|
pub generation: Generation,
|
|
|
|
pub repo_alias: RepoAlias,
|
|
|
|
pub repo_path: RepoPath,
|
|
|
|
pub branch: BranchName,
|
|
|
|
pub forge: ForgeDetails,
|
|
|
|
pub repo_config: Option<RepoConfig>,
|
|
|
|
pub gitdir: GitDir,
|
|
|
|
}
|
|
|
|
impl RepoDetails {
|
|
|
|
pub fn new(
|
|
|
|
generation: Generation,
|
|
|
|
repo_alias: &RepoAlias,
|
|
|
|
server_repo_config: &ServerRepoConfig,
|
2024-05-29 19:22:05 +01:00
|
|
|
forge_alias: &ForgeAlias,
|
2024-05-11 19:46:20 +01:00
|
|
|
forge_config: &ForgeConfig,
|
|
|
|
gitdir: GitDir,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
generation,
|
|
|
|
repo_alias: repo_alias.clone(),
|
2024-05-15 07:55:05 +01:00
|
|
|
repo_path: server_repo_config.repo(),
|
2024-05-11 19:46:20 +01:00
|
|
|
repo_config: server_repo_config.repo_config(),
|
2024-05-15 07:55:05 +01:00
|
|
|
branch: server_repo_config.branch(),
|
2024-05-11 19:46:20 +01:00
|
|
|
gitdir,
|
2024-05-15 07:55:05 +01:00
|
|
|
forge: ForgeDetails::new(
|
2024-05-29 19:22:05 +01:00
|
|
|
forge_alias.clone(),
|
2024-05-15 07:55:05 +01:00
|
|
|
forge_config.forge_type(),
|
|
|
|
forge_config.hostname(),
|
|
|
|
forge_config.user(),
|
|
|
|
forge_config.token(),
|
|
|
|
),
|
2024-05-11 19:46:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn origin(&self) -> secrecy::Secret<String> {
|
|
|
|
let repo_details = self;
|
2024-05-15 07:55:05 +01:00
|
|
|
let user = &repo_details.forge.user();
|
|
|
|
let hostname = &repo_details.forge.hostname();
|
2024-05-11 19:46:20 +01:00
|
|
|
let repo_path = &repo_details.repo_path;
|
2024-05-15 07:55:05 +01:00
|
|
|
let expose_secret = repo_details.forge.token();
|
2024-05-11 19:46:20 +01:00
|
|
|
use secrecy::ExposeSecret;
|
|
|
|
let token = expose_secret.expose_secret();
|
|
|
|
let origin = format!("https://{user}:{token}@{hostname}/{repo_path}.git");
|
|
|
|
origin.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn git_remote(&self) -> GitRemote {
|
2024-05-15 07:55:05 +01:00
|
|
|
GitRemote::new(self.forge.hostname().clone(), self.repo_path.clone())
|
2024-05-11 19:46:20 +01:00
|
|
|
}
|
|
|
|
}
|