Skip to content

Commit

Permalink
feat: use git[+subprotocol] pattern
Browse files Browse the repository at this point in the history
See helm/community#321

Signed-off-by: Dominykas Blyžė <hello@dominykas.com>
  • Loading branch information
dominykas committed Dec 15, 2023
1 parent 5b7d78f commit 2604e1f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
16 changes: 8 additions & 8 deletions internal/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,47 +149,47 @@ func TestResolve(t *testing.T) {
{
name: "repo from git https url",
req: []*chart.Dependency{
{Name: "gitdependencyok", Repository: "git://https://github.com/helm/helmchart.git", Version: "1.0.0"},
{Name: "gitdependencyok", Repository: "git+https://github.com/helm/helmchart.git", Version: "1.0.0"},
},
expect: &chart.Lock{
Dependencies: []*chart.Dependency{
{Name: "gitdependencyok", Repository: "git://https://github.com/helm/helmchart.git", Version: "1.0.0"},
{Name: "gitdependencyok", Repository: "git+https://github.com/helm/helmchart.git", Version: "1.0.0"},
},
},
err: false,
},
{
name: "repo from git https url",
req: []*chart.Dependency{
{Name: "gitdependencyerror", Repository: "git://https://github.com/helm/helmchart.git", Version: "2.0.0"},
{Name: "gitdependencyerror", Repository: "git+https://github.com/helm/helmchart.git", Version: "2.0.0"},
},
expect: &chart.Lock{
Dependencies: []*chart.Dependency{
{Name: "gitdependencyerror", Repository: "git://https://github.com/helm/helmchart.git", Version: "2.0.0"},
{Name: "gitdependencyerror", Repository: "git+https://github.com/helm/helmchart.git", Version: "2.0.0"},
},
},
err: true,
},
{
name: "repo from git ssh url",
req: []*chart.Dependency{
{Name: "gitdependency", Repository: "git://git@github.com:helm/helmchart.git", Version: "1.0.0"},
{Name: "gitdependency", Repository: "git://github.com:helm/helmchart.git", Version: "1.0.0"},
},
expect: &chart.Lock{
Dependencies: []*chart.Dependency{
{Name: "gitdependency", Repository: "git://git@github.com:helm/helmchart.git", Version: "1.0.0"},
{Name: "gitdependency", Repository: "git://github.com:helm/helmchart.git", Version: "1.0.0"},
},
},
err: false,
},
{
name: "repo from git ssh url",
req: []*chart.Dependency{
{Name: "gitdependencyerror", Repository: "git://git@github.com:helm/helmchart.git", Version: "2.0.0"},
{Name: "gitdependencyerror", Repository: "git://github.com:helm/helmchart.git", Version: "2.0.0"},
},
expect: &chart.Lock{
Dependencies: []*chart.Dependency{
{Name: "gitdependencyerror", Repository: "git://git@github.com:helm/helmchart.git", Version: "2.0.0"},
{Name: "gitdependencyerror", Repository: "git://github.com:helm/helmchart.git", Version: "2.0.0"},
},
},
err: true,
Expand Down
3 changes: 2 additions & 1 deletion pkg/downloader/chart_downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func TestResolveChartRef(t *testing.T) {
{name: "full URL", ref: "http://example.com/foo-1.2.3.tgz", expect: "http://example.com/foo-1.2.3.tgz"},
{name: "full URL, HTTPS", ref: "https://example.com/foo-1.2.3.tgz", expect: "https://example.com/foo-1.2.3.tgz"},
{name: "full URL, with authentication", ref: "http://username:password@example.com/foo-1.2.3.tgz", expect: "http://username:password@example.com/foo-1.2.3.tgz"},
{name: "helmchart", ref: "git://https://github.com/helmchart/helmchart.git", expect: "https://github.com/helmchart/helmchart.git"},
{name: "helmchart", ref: "git+https://github.com/helmchart/helmchart.git", expect: "https://github.com/helmchart/helmchart.git"},
{name: "helmchart", ref: "git://github.com/helmchart/helmchart.git", expect: "git://github.com/helmchart/helmchart.git"},
{name: "reference, testing repo", ref: "testing/alpine", expect: "http://example.com/alpine-1.2.3.tgz"},
{name: "reference, version, testing repo", ref: "testing/alpine", version: "0.2.0", expect: "http://example.com/alpine-0.2.0.tgz"},
{name: "reference, version, malformed repo", ref: "malformed/alpine", version: "1.2.3", expect: "http://dl.example.com/alpine-1.2.3.tgz"},
Expand Down
6 changes: 3 additions & 3 deletions pkg/downloader/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestFindChartURL(t *testing.T) {
}{
{name: "alpine", version: "0.1.0", repoURL: "http://example.com/charts", expectChurl: "https://charts.helm.sh/stable/alpine-0.1.0.tgz", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: false, expectPasscredentialsall: false},
{name: "tlsfoo", version: "1.2.3", repoURL: "https://example-https-insecureskiptlsverify.com", expectChurl: "https://example.com/tlsfoo-1.2.3.tgz", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: true, expectPasscredentialsall: false},
{name: "helm-test", version: "master", repoURL: "git://https://github.com/rally25rs/helm-test-chart.git", expectChurl: "git://https://github.com/rally25rs/helm-test-chart.git", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: false, expectPasscredentialsall: false},
{name: "helm-test", version: "master", repoURL: "git+https://github.com/rally25rs/helm-test-chart.git", expectChurl: "git+https://github.com/rally25rs/helm-test-chart.git", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: false, expectPasscredentialsall: false},
}
for _, tt := range tests {
churl, username, password, insecureSkipTLSVerify, passcredentialsall, _, _, _, err := m.findChartURL(tt.name, tt.version, tt.repoURL, repos)
Expand Down Expand Up @@ -177,9 +177,9 @@ func TestGetRepoNames(t *testing.T) {
{
name: "repo from git url",
req: []*chart.Dependency{
{Name: "local-dep", Repository: "git://https://github.com/git/git"},
{Name: "local-dep", Repository: "git+https://github.com/git/git"},
},
expect: map[string]string{"local-dep": "git://https://github.com/git/git"},
expect: map[string]string{"local-dep": "git+https://github.com/git/git"},
},
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/gitutil/gitutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ package gitutil

import (
"os"
"regexp"
"strings"

"github.com/Masterminds/vcs"
)

var gitRepositoryUrlRe = regexp.MustCompile("^git(\\+\\w+)?://")

Check failure on line 27 in pkg/gitutil/gitutil.go

View workflow job for this annotation

GitHub Actions / build

var-naming: var gitRepositoryUrlRe should be gitRepositoryURLRe (revive)

// HasGitReference returns true if a git repository contains a specified ref (branch/tag)
func HasGitReference(gitRepo, ref, repoName string) (bool, error) {
local, err := os.MkdirTemp("", repoName)
Expand All @@ -44,10 +47,10 @@ func HasGitReference(gitRepo, ref, repoName string) (bool, error) {

// IsGitRepository determines whether a URL is to be treated as a git repository URL
func IsGitRepository(url string) bool {
return strings.HasPrefix(url, "git://")
return gitRepositoryUrlRe.MatchString(url)
}

// RepositoryURLToGitURL converts a repository URL into a URL that `git clone` could consume
func RepositoryURLToGitURL(url string) string {
return strings.TrimPrefix(url, "git://")
return strings.TrimPrefix(url, "git+")
}
2 changes: 1 addition & 1 deletion pkg/gitutil/gitutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestIsGitUrl(t *testing.T) {
}{
{"oci://example.com/example/chart", false},
{"git://example.com/example/chart", true},
{"git://https://example.com/example/chart", true},
{"git+https://example.com/example/chart", true},
}

for _, test := range tests {
Expand Down

0 comments on commit 2604e1f

Please sign in to comment.