git_next_core/config/
repo_config.rs

1use crate::config::{RepoBranches, RepoConfigSource};
2
3/// Mapped from `.git-next.toml` file in target repo
4/// Is also derived from the optional parameters in `git-next-server.toml` at
5/// `forge.{forge}.repos.{repo}.(main|next|dev)`
6#[derive(
7    Clone,
8    Hash,
9    Debug,
10    PartialEq,
11    Eq,
12    PartialOrd,
13    Ord,
14    serde::Deserialize,
15    serde::Serialize,
16    derive_more::Constructor,
17    derive_more::Display,
18    derive_with::With,
19)]
20#[display("{}", branches)]
21pub struct RepoConfig {
22    branches: RepoBranches,
23    source: RepoConfigSource,
24}
25impl RepoConfig {
26    /// Parses the TOML document into a `RepoConfig`.
27    ///
28    /// # Errors
29    ///
30    /// Will return `Err` if the TOML file is invalid or otherwise doesn't
31    /// match a `RepoConfig`.
32    pub fn parse(toml: &str) -> Result<Self, toml::de::Error> {
33        toml::from_str(format!("source = \"Repo\"\n{toml}").as_str())
34    }
35
36    #[must_use]
37    pub const fn branches(&self) -> &RepoBranches {
38        &self.branches
39    }
40
41    #[must_use]
42    pub const fn source(&self) -> RepoConfigSource {
43        self.source
44    }
45}