From 1acce654622a6511589b940fe0716cd1ba6e2b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=A3o=20Mata?= Date: Wed, 29 Jul 2020 14:06:47 +0200 Subject: [PATCH] feat(package): Add support for Helm charts (#1525) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simão Mata --- docs/config/README.md | 4 +++- src/modules/package.rs | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/config/README.md b/docs/config/README.md index 745cb5f1..c551e7a5 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1575,7 +1575,7 @@ format = "via [🤖 $version](bold green) " The `package` module is shown when the current directory is the repository for a package, and shows its current version. The module currently supports `npm`, `cargo`, -`poetry`, `composer`, `gradle`, `julia` and `mix` packages. +`poetry`, `composer`, `gradle`, `julia`, `mix` and `helm` packages. - **npm** – The `npm` package version is extracted from the `package.json` present in the current directory @@ -1588,6 +1588,8 @@ package, and shows its current version. The module currently supports `npm`, `ca - **gradle** – The `gradle` package version is extracted from the `build.gradle` present - **julia** - The package version is extracted from the `Project.toml` present - **mix** - The `mix` package version is extracted from the `mix.exs` present +- **helm** - The `helm` chart version is extracted from the `Chart.yaml` present + > ⚠️ The version being shown is that of the package whose source code is in your > current directory, not your package manager. diff --git a/src/modules/package.rs b/src/modules/package.rs index cb79c480..c7ff4550 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -108,6 +108,12 @@ fn extract_project_version(file_contents: &str) -> Option { Some(formatted_version) } +fn extract_helm_package_version(file_contents: &str) -> Option { + let yaml = yaml_rust::YamlLoader::load_from_str(file_contents).ok()?; + let version = yaml.first()?["version"].as_str()?; + Some(format_version(version)) +} + fn extract_mix_version(file_contents: &str) -> Option { let re = Regex::new(r#"(?m)version: "(?P[^"]+)""#).unwrap(); let caps = re.captures(file_contents)?; @@ -131,6 +137,8 @@ fn get_package_version(base_dir: &PathBuf, config: &PackageConfig) -> Option io::Result<()> { + let config_name = "Chart.yaml"; + let config_content = " + apiVersion: v1 + name: starship + version: 0.2.0 + "; + + let project_dir = create_project_dir()?; + fill_config(&project_dir, config_name, Some(&config_content))?; + expect_output(&project_dir, Some("v0.2.0"), None)?; + project_dir.close() + } + #[test] fn test_extract_composer_version() -> io::Result<()> { let config_name = "composer.json";