From 9f025a384fb9062aa61401b8f8ebfc02d5e36a2e Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Tue, 9 Jul 2024 18:59:25 +0200 Subject: [PATCH] feat: allow empty file path (#284) --- README.md | 9 ++++++--- helm-git-plugin.sh | 9 ++++++--- tests/04-uri-parsing.bats | 7 +++++++ tests/04-uri-validation.bats | 5 +++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index baef262e..17f6e166 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,16 @@ to the plugin, please see [these instructions](.github/CONTRIBUTING.md). Here's the Git urls format, followed by examples: - git+https://[provider.com]/[user]/[repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]] - git+ssh://git@[provider.com]/[user]/[repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]] - git+file://[path/to/repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]] + git+https://[provider.com]/[user]/[repo][@path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]] + git+ssh://git@[provider.com]/[user]/[repo][@path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]] + git+file://[path/to/repo][@path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]] git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2&sparse=0 git+ssh://git@github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2&sparse=1 git+ssh://git@github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2 git+https://github.com/istio/istio@install/kubernetes/helm?ref=1.5.4&sparse=0&depupdate=0 git+https://github.com/bitnami/charts@bitnami/wordpress?ref=master&sparse=0&depupdate=0&package=0 + git+https://gitlab.com/one-touch-pipeline/weskit/helm-deployment?ref=ee259f65191cef10855438321ce99e37873918b6 Add your repository: @@ -103,6 +104,8 @@ You can enable debug output by setting `HELM_GIT_DEBUG` environment variable to In order to debug in a more efficient maneer, I advise you use `helm fetch` instead of `helm repo add`. +You can enable more advanced output by setting `HELM_GIT_TRACE` environment variable to `1`. + ## Contributing Contributions are welcome! Please see [these instructions](.github/CONTRIBUTING.md) that will help you to develop the plugin. diff --git a/helm-git-plugin.sh b/helm-git-plugin.sh index fa9b983e..f6de8a4f 100755 --- a/helm-git-plugin.sh +++ b/helm-git-plugin.sh @@ -294,10 +294,13 @@ parse_uri() { string_contains "$allowed_protocols" "$_git_scheme" || error "$error_invalid_protocol" - _git_path=$(echo "${_uri_path}" | cut -d'@' -f 1) + _git_path=$(echo "${_uri_path}" | awk -F'@' '{print $1}') + _git_file_path=$(echo "${_uri_path}" | awk -F'@' '{print $2}') + if [ -z "$_git_file_path" ]; then + _git_file_path=$(basename "$_git_path") + _git_path=$(dirname "$_git_path") + fi trace "_git_path: $_git_path" - - _git_file_path=$(echo "${_uri_path}" | cut -d'@' -f 2) trace "_git_file_path: $_git_file_path" helm_dir=$(dirname "${_git_file_path}" | sed -r '/^[\.|/]$/d') diff --git a/tests/04-uri-parsing.bats b/tests/04-uri-parsing.bats index b096b8c8..5a483283 100644 --- a/tests/04-uri-parsing.bats +++ b/tests/04-uri-parsing.bats @@ -86,3 +86,10 @@ load 'test-helper' [ $helm_dir = "charts/gitlab" ] [ $git_ref = "master" ] } + +@test "should discover path without path separator" { + parse_uri "git+https://github.com/jetstack/cert-manager/index.yaml" + [ $git_repo = "https://github.com/jetstack/cert-manager" ] + [ -z $helm_dir ] + [ $helm_file = "index.yaml" ] +} diff --git a/tests/04-uri-validation.bats b/tests/04-uri-validation.bats index b61138db..4dfd067e 100644 --- a/tests/04-uri-validation.bats +++ b/tests/04-uri-validation.bats @@ -73,3 +73,8 @@ load 'test-helper' _run_helm_git "git+https://github.com/hashicorp/vault-helm@/index.yaml?ref=v0.5.0" [ $status = 0 ] } + +@test "should success with empty inline git_file_path" { + _run_helm_git "git+https://gitlab.com/one-touch-pipeline/weskit/helm-deployment/index.yaml?ref=ee259f65191cef10855438321ce99e37873918b6" + [ $status = 0 ] +}