2024-05-11 19:46:20 +01:00
|
|
|
use git_next_config::{
|
|
|
|
BranchName, ForgeConfig, ForgeDetails, ForgeName, GitDir, RepoAlias, RepoConfig, RepoPath,
|
|
|
|
ServerRepoConfig,
|
|
|
|
};
|
|
|
|
|
|
|
|
use super::{Generation, GitRemote};
|
|
|
|
|
|
|
|
/// The derived information about a repo, used to interact with it
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
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,
|
|
|
|
forge_name: &ForgeName,
|
|
|
|
forge_config: &ForgeConfig,
|
|
|
|
gitdir: GitDir,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
generation,
|
|
|
|
repo_alias: repo_alias.clone(),
|
|
|
|
repo_path: RepoPath(server_repo_config.repo.clone()),
|
|
|
|
repo_config: server_repo_config.repo_config(),
|
2024-05-12 22:27:20 +01:00
|
|
|
branch: BranchName::new(&server_repo_config.branch),
|
2024-05-11 19:46:20 +01:00
|
|
|
gitdir,
|
|
|
|
forge: ForgeDetails {
|
|
|
|
forge_name: forge_name.clone(),
|
2024-05-12 22:27:20 +01:00
|
|
|
forge_type: forge_config.forge_type(),
|
2024-05-11 19:46:20 +01:00
|
|
|
hostname: forge_config.hostname(),
|
|
|
|
user: forge_config.user(),
|
|
|
|
token: forge_config.token(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn origin(&self) -> secrecy::Secret<String> {
|
|
|
|
let repo_details = self;
|
|
|
|
let user = &repo_details.forge.user;
|
|
|
|
let hostname = &repo_details.forge.hostname;
|
|
|
|
let repo_path = &repo_details.repo_path;
|
|
|
|
use secrecy::ExposeSecret;
|
|
|
|
let expose_secret = &repo_details.forge.token;
|
|
|
|
let token = expose_secret.expose_secret();
|
|
|
|
let origin = format!("https://{user}:{token}@{hostname}/{repo_path}.git");
|
|
|
|
origin.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn git_remote(&self) -> GitRemote {
|
|
|
|
GitRemote::new(self.forge.hostname.clone(), self.repo_path.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::fmt::Display for RepoDetails {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"gen-{}:{}:{}/{}:{}@{}/{}@{}",
|
|
|
|
self.generation,
|
|
|
|
self.forge.forge_type,
|
|
|
|
self.forge.forge_name,
|
|
|
|
self.repo_alias,
|
|
|
|
self.forge.user,
|
|
|
|
self.forge.hostname,
|
|
|
|
self.repo_path,
|
|
|
|
self.branch,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|