Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ func (g *Git) GetPushURL(remote string, token string) (string, error) {
return "", err
}

pushURLArray := strings.SplitAfter(strings.TrimSpace(string(pushURL)), "https://")
pushURLWithToken := fmt.Sprintf("https://x-access-token:%s@%s", token, pushURLArray[1])
pushURLStr := string(pushURL)
found := false

if pushURLStr, found = strings.CutPrefix(pushURLStr, "git@"); found {
pushURLStr = strings.ReplaceAll(pushURLStr, ":", "/")
pushURLStr = strings.TrimSuffix(pushURLStr, ".git\n")
} else {
pushURLStr = strings.TrimPrefix(pushURLStr, "https://")
}
pushURLWithToken := fmt.Sprintf("https://x-access-token:%s@%s", token, strings.Trim(pushURLStr, "\n"))
return pushURLWithToken, nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (r *Releaser) UpdateIndexFile() (bool, error) {
packageName, packageVersion := tagParts[0], tagParts[1]
fmt.Printf("Found %s-%s.tgz\n", packageName, packageVersion)
if _, err := indexFile.Get(packageName, packageVersion); err != nil {
if err := r.addToIndexFile(indexFile, downloadURL.String()); err != nil {
if err := r.addToIndexFile(indexFile, downloadURL.String(), name); err != nil {
return false, err
}
update = true
Expand Down Expand Up @@ -267,8 +267,8 @@ func (r *Releaser) splitPackageNameAndVersion(pkg string) []string {
return []string{pkg[0:delimIndex], pkg[delimIndex+1:]}
}

func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error {
arch := filepath.Join(r.config.PackagePath, filepath.Base(url))
func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, downloadUrl, fileName string) error {
arch := filepath.Join(r.config.PackagePath, filepath.Base(fileName))

// extract chart metadata
fmt.Printf("Extracting chart metadata from %s\n", arch)
Expand All @@ -286,7 +286,7 @@ func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error {
// remove url name from url as helm's index library
// adds it in during .Add
// there should be a better way to handle this :(
s := strings.Split(url, "/")
s := strings.Split(downloadUrl, "/")
s = s[:len(s)-1]

if r.config.PackagesWithIndex {
Expand Down
22 changes: 20 additions & 2 deletions pkg/releaser/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
name string
chart string
version string
filename string
releaser *Releaser
packagesWithIndex bool
error bool
Expand All @@ -296,6 +297,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
"invalid-package",
"does-not-exist",
"0.1.0",
"missing-test-chart-0.1.0.tgz",
&Releaser{
config: &config.Options{
PackagePath: "testdata/release-packages",
Expand All @@ -309,6 +311,21 @@ func TestReleaser_addToIndexFile(t *testing.T) {
"valid-package",
"test-chart",
"0.1.0",
"test-chart-0.1.0.tgz",
&Releaser{
config: &config.Options{
PackagePath: "testdata/release-packages",
PackagesWithIndex: false,
},
},
false,
false,
},
{
"valid-package-extra-sem-ver",
"test-chart",
"0.1.0+Chart1",
"test-chart-0.1.0+Chart1.tgz",
&Releaser{
config: &config.Options{
PackagePath: "testdata/release-packages",
Expand All @@ -322,6 +339,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
"valid-package-with-index",
"test-chart",
"0.1.0",
"test-chart-0.1.0.tgz",
&Releaser{
config: &config.Options{
PackagePath: "testdata/release-packages",
Expand All @@ -336,7 +354,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
indexFile := repo.NewIndexFile()
url := fmt.Sprintf("https://myrepo/charts/%s-%s.tgz", tt.chart, tt.version)
err := tt.releaser.addToIndexFile(indexFile, url)
err := tt.releaser.addToIndexFile(indexFile, url, tt.filename)
if tt.error {
assert.Error(t, err)
assert.False(t, indexFile.Has(tt.chart, tt.version))
Expand Down Expand Up @@ -467,7 +485,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
assert.Equal(t, tt.commit, fakeGitHub.release.Commit)
assert.Equal(t, tt.latest, fakeGitHub.release.MakeLatest)
assert.Equal(t, tt.Releaser.config.Commit, fakeGitHub.release.Commit)
fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 1)
fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 2)
}
})
}
Expand Down
Binary file not shown.