diff --git a/src/core/repo_graph.rs b/src/core/repo_graph.rs index 15b9584..22c025e 100644 --- a/src/core/repo_graph.rs +++ b/src/core/repo_graph.rs @@ -1,19 +1,19 @@ use std::fs; use std::path::Path; -use toml::Value as TomlValue; mod builder; mod generic; mod go; mod helpers; mod impact; +mod manifest; mod node; mod python; mod rust; mod types; use builder::RepoGraphBuilder; -use helpers::{display_path, normalize_path}; +use helpers::display_path; pub use impact::analyze_impact; pub use types::*; @@ -66,18 +66,3 @@ fn detect_ignored_paths(root: &Path, builder: &mut RepoGraphBuilder) { } } } - -fn manifest_warning_category(message: &str) -> DetectionCategory { - if message.starts_with("Failed to read") { - DetectionCategory::UnreadableManifest - } else { - DetectionCategory::MalformedManifest - } -} - -fn read_toml(path: &Path) -> Result { - fs::read_to_string(path) - .map_err(|error| format!("Failed to read {}: {error}", normalize_path(path)))? - .parse::() - .map_err(|error| format!("Failed to parse {}: {error}", normalize_path(path))) -} diff --git a/src/core/repo_graph/manifest.rs b/src/core/repo_graph/manifest.rs new file mode 100644 index 0000000..1f53e02 --- /dev/null +++ b/src/core/repo_graph/manifest.rs @@ -0,0 +1,22 @@ +use std::fs; +use std::path::Path; + +use toml::Value as TomlValue; + +use super::helpers::normalize_path; +use super::types::DetectionCategory; + +pub(super) fn manifest_warning_category(message: &str) -> DetectionCategory { + if message.starts_with("Failed to read") { + DetectionCategory::UnreadableManifest + } else { + DetectionCategory::MalformedManifest + } +} + +pub(super) fn read_toml(path: &Path) -> Result { + fs::read_to_string(path) + .map_err(|error| format!("Failed to read {}: {error}", normalize_path(path)))? + .parse::() + .map_err(|error| format!("Failed to parse {}: {error}", normalize_path(path))) +} diff --git a/src/core/repo_graph/node.rs b/src/core/repo_graph/node.rs index 7c8c918..587aa42 100644 --- a/src/core/repo_graph/node.rs +++ b/src/core/repo_graph/node.rs @@ -3,8 +3,9 @@ use std::fs; use std::path::Path; use super::helpers::normalize_path; +use super::manifest::manifest_warning_category; use super::types::*; -use super::{manifest_warning_category, RepoGraphBuilder}; +use super::RepoGraphBuilder; pub(super) fn detect_node(root: &Path, builder: &mut RepoGraphBuilder) { let package_json = root.join("package.json"); diff --git a/src/core/repo_graph/python.rs b/src/core/repo_graph/python.rs index 20b723c..892d863 100644 --- a/src/core/repo_graph/python.rs +++ b/src/core/repo_graph/python.rs @@ -2,8 +2,9 @@ use std::fs; use std::path::Path; use toml::Value as TomlValue; +use super::manifest::{manifest_warning_category, read_toml}; use super::types::*; -use super::{manifest_warning_category, read_toml, RepoGraphBuilder}; +use super::RepoGraphBuilder; pub(super) fn detect_python(root: &Path, builder: &mut RepoGraphBuilder) { let mut python_project_detected = false; diff --git a/src/core/repo_graph/rust.rs b/src/core/repo_graph/rust.rs index 97e23f0..50e5dee 100644 --- a/src/core/repo_graph/rust.rs +++ b/src/core/repo_graph/rust.rs @@ -3,8 +3,9 @@ use std::path::{Path, PathBuf}; use toml::Value as TomlValue; use super::helpers::{normalize_path, stable_id}; +use super::manifest::{manifest_warning_category, read_toml}; use super::types::*; -use super::{manifest_warning_category, read_toml, RepoGraphBuilder}; +use super::RepoGraphBuilder; struct CargoWorkspaceMember { relative_manifest: PathBuf,