Skip to content

Commit

Permalink
feat: allow empty file path (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslafy-z authored Jul 9, 2024
1 parent 7640834 commit 9f025a3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
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://[email protected]/jetstack/cert-manager@deploy/charts?ref=v0.6.2&sparse=1
git+ssh://[email protected]/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 ]
}

0 comments on commit 9f025a3

Please sign in to comment.