git_next_core/config/
forge_details.rs

1use crate::config::{ApiToken, ForgeAlias, ForgeConfig, ForgeType, Hostname, User};
2
3use super::CommitCount;
4
5/// The derived information about a Forge, used to create interactions with it
6#[derive(Clone, Default, Debug, derive_more::Constructor, derive_with::With)]
7pub struct ForgeDetails {
8    forge_alias: ForgeAlias,
9    forge_type: ForgeType,
10    hostname: Hostname,
11    user: User,
12    token: ApiToken,
13    max_dev_commits: Option<CommitCount>,
14}
15impl ForgeDetails {
16    #[must_use]
17    pub const fn forge_alias(&self) -> &ForgeAlias {
18        &self.forge_alias
19    }
20
21    #[must_use]
22    pub const fn forge_type(&self) -> ForgeType {
23        self.forge_type
24    }
25
26    #[must_use]
27    pub const fn hostname(&self) -> &Hostname {
28        &self.hostname
29    }
30
31    pub(crate) const fn user(&self) -> &User {
32        &self.user
33    }
34
35    #[must_use]
36    pub const fn token(&self) -> &ApiToken {
37        &self.token
38    }
39
40    #[must_use]
41    pub const fn max_dev_commits(&self) -> Option<&CommitCount> {
42        self.max_dev_commits.as_ref()
43    }
44}
45impl From<(&ForgeAlias, &ForgeConfig)> for ForgeDetails {
46    fn from((forge_alias, forge_config): (&ForgeAlias, &ForgeConfig)) -> Self {
47        Self {
48            forge_alias: forge_alias.clone(),
49            forge_type: forge_config.forge_type(),
50            hostname: forge_config.hostname(),
51            user: forge_config.user(),
52            token: forge_config.token(),
53            max_dev_commits: forge_config.max_dev_commits(),
54        }
55    }
56}