Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow empty file path #284

Merged
merged 12 commits into from
Jul 9, 2024
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions helm-git-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions tests/04-uri-parsing.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
5 changes: 5 additions & 0 deletions tests/04-uri-validation.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
Loading