1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::config::{RepoBranches, RepoConfigSource};

/// Mapped from `.git-next.toml` file in target repo
/// Is also derived from the optional parameters in `git-next-server.toml` at
/// `forge.{forge}.repos.{repo}.(main|next|dev)`
#[derive(
    Clone,
    Hash,
    Debug,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    serde::Deserialize,
    serde::Serialize,
    derive_more::Constructor,
    derive_more::Display,
    derive_with::With,
)]
#[display("{}", branches)]
pub struct RepoConfig {
    branches: RepoBranches,
    source: RepoConfigSource,
}
impl RepoConfig {
    /// Parses the TOML document into a `RepoConfig`.
    ///
    /// # Errors
    ///
    /// Will return `Err` if the TOML file is invalid or otherwise doesn't
    /// match a `RepoConfig`.
    pub fn parse(toml: &str) -> Result<Self, toml::de::Error> {
        toml::from_str(format!("source = \"Repo\"\n{toml}").as_str())
    }

    #[must_use]
    pub const fn branches(&self) -> &RepoBranches {
        &self.branches
    }

    #[must_use]
    pub const fn source(&self) -> RepoConfigSource {
        self.source
    }
}