aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ba/back/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ba/back/src/config')
-rw-r--r--pkgs/by-name/ba/back/src/config/mod.rs72
1 files changed, 22 insertions, 50 deletions
diff --git a/pkgs/by-name/ba/back/src/config/mod.rs b/pkgs/by-name/ba/back/src/config/mod.rs
index 1161ce3..789c0b0 100644
--- a/pkgs/by-name/ba/back/src/config/mod.rs
+++ b/pkgs/by-name/ba/back/src/config/mod.rs
@@ -23,26 +23,25 @@ use crate::{
git_bug::dag::is_git_bug,
};
+#[derive(Deserialize)]
pub struct BackConfig {
/// The url to the source code of back. This is needed, because back is licensed under the
/// AGPL.
pub source_code_repository_url: Url,
- /// A list of the repositories known to back.
- /// This list is constructed from the `scan_path` and the `project_list` file.
- pub repositories: BackRepositories,
-
/// The root url this instance of back is hosted on.
/// For example:
/// `issues.foss-syndicate.org`
- pub root: Url,
+ pub root_url: Url,
+
+ project_list: PathBuf,
+
+ /// The path that is the common parent of all the repositories.
+ pub scan_path: PathBuf,
}
pub struct BackRepositories {
repositories: Vec<BackRepository>,
-
- /// The path that is the common parent of all the repositories.
- scan_path: PathBuf,
}
impl BackRepositories {
@@ -72,10 +71,6 @@ impl BackRepositories {
repository_path: path.to_owned(),
})
}
-
- pub fn scan_path(&self) -> &Path {
- &self.scan_path
- }
}
pub struct BackRepository {
@@ -103,39 +98,12 @@ impl BackRepository {
}
}
-#[derive(Deserialize)]
-struct RawBackConfig {
- source_code_repository_url: Url,
- root_url: Url,
- project_list: PathBuf,
- scan_path: PathBuf,
-}
-
impl BackConfig {
- pub fn from_config_file(path: &Path) -> error::Result<Self> {
- let value = fs::read_to_string(path).map_err(|err| Error::ConfigRead {
- file: path.to_owned(),
- error: err,
- })?;
-
- let raw: RawBackConfig =
- serde_json::from_str(&value).map_err(|err| Error::ConfigParse {
- file: path.to_owned(),
- error: err,
- })?;
-
- Self::try_from(raw)
- }
-}
-
-impl TryFrom<RawBackConfig> for BackConfig {
- type Error = error::Error;
-
- fn try_from(value: RawBackConfig) -> Result<Self, Self::Error> {
- let repositories = fs::read_to_string(&value.project_list)
+ pub fn repositories(&self) -> error::Result<BackRepositories> {
+ let repositories = fs::read_to_string(&self.project_list)
.map_err(|err| error::Error::ProjectListRead {
error: err,
- file: value.project_list,
+ file: self.project_list.to_owned(),
})?
.lines()
.try_fold(vec![], |mut acc, path| {
@@ -143,16 +111,20 @@ impl TryFrom<RawBackConfig> for BackConfig {
repo_path: PathBuf::from(path),
});
- Ok::<_, Self::Error>(acc)
+ Ok::<_, error::Error>(acc)
})?;
+ Ok(BackRepositories { repositories })
+ }
- Ok(Self {
- source_code_repository_url: value.source_code_repository_url,
- repositories: BackRepositories {
- repositories,
- scan_path: value.scan_path,
- },
- root: value.root_url,
+ pub fn from_config_file(path: &Path) -> error::Result<Self> {
+ let value = fs::read_to_string(path).map_err(|err| Error::ConfigRead {
+ file: path.to_owned(),
+ error: err,
+ })?;
+
+ serde_json::from_str(&value).map_err(|err| Error::ConfigParse {
+ file: path.to_owned(),
+ error: err,
})
}
}