1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-13 00:36:30 +00:00

feat(package): Add support for Helm charts (#1525)

Signed-off-by: Simão Mata <sm@0io.eu>
This commit is contained in:
Simão Mata 2020-07-29 14:06:47 +02:00 committed by GitHub
parent dfe331bf4e
commit 1acce65462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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.

View File

@ -108,6 +108,12 @@ fn extract_project_version(file_contents: &str) -> Option<String> {
Some(formatted_version)
}
fn extract_helm_package_version(file_contents: &str) -> Option<String> {
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<String> {
let re = Regex::new(r#"(?m)version: "(?P<version>[^"]+)""#).unwrap();
let caps = re.captures(file_contents)?;
@ -131,6 +137,8 @@ fn get_package_version(base_dir: &PathBuf, config: &PackageConfig) -> Option<Str
extract_project_version(&project_toml)
} else if let Ok(mix_file) = utils::read_file(base_dir.join("mix.exs")) {
extract_mix_version(&mix_file)
} else if let Ok(chart_file) = utils::read_file(base_dir.join("Chart.yaml")) {
extract_helm_package_version(&chart_file)
} else {
None
}
@ -463,6 +471,21 @@ end";
project_dir.close()
}
#[test]
fn test_extract_helm_chart_version() -> 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";