Skip to content

Commit

Permalink
🌊 support azure repos (#664)
Browse files Browse the repository at this point in the history
* support azure repos

* return error if no files found
  • Loading branch information
petar-cvit authored Oct 30, 2024
1 parent d2ca579 commit 958a896
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
27 changes: 24 additions & 3 deletions cyclops-ctrl/internal/template/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/protocol/packp/capability"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"
"helm.sh/helm/v3/pkg/chart"
Expand Down Expand Up @@ -82,6 +84,10 @@ func (r Repo) LoadTemplate(repoURL, path, commit, resolvedVersion string) (*mode
}
// endregion

if len(files) == 0 {
return nil, errors.Errorf("no files found in repo %v on path %v; make sure the repo, path and version are correct", repoURL, path)
}

// region map files to template
metadataBytes := []byte{}
schemaBytes := []byte{}
Expand Down Expand Up @@ -112,13 +118,22 @@ func (r Repo) LoadTemplate(repoURL, path, commit, resolvedVersion string) (*mode
}

if len(parts) > 1 && parts[0] == "crds" &&
(parts[1] != "Notes.txt" && parts[1] != "NOTES.txt") {
(parts[1] != "Notes.txt" && parts[1] != "NOTES.txt" && parts[1] != "tests") {
crdFiles = append(crdFiles, f)
continue
}

chartFiles = append(chartFiles, f)
if len(parts) > 2 && parts[0] == "charts" {
depName := parts[1]
if _, ok := dependenciesFromChartsDir[depName]; !ok {
dependenciesFromChartsDir[depName] = make(map[string][]byte)
}

dependenciesFromChartsDir[depName][path2.Join(parts[1:]...)] = f.Data
continue
}

chartFiles = append(chartFiles, f)
}

var schema helm.Property
Expand All @@ -132,7 +147,7 @@ func (r Repo) LoadTemplate(repoURL, path, commit, resolvedVersion string) (*mode

var metadata *helm.Metadata
if err := yaml.Unmarshal(metadataBytes, &metadata); err != nil {
fmt.Println("error on meta unm", repoURL, path)
fmt.Println("error on meta unmarshal", repoURL, path)
return &models.Template{}, err
}

Expand Down Expand Up @@ -337,6 +352,12 @@ func readValuesFile(fs billy.Filesystem, path string) ([]byte, error) {

func clone(repoURL, commit string, creds *auth.Credentials) (billy.Filesystem, error) {
// region clone from git
if gitproviders.IsAzureRepo(repoURL) {
transport.UnsupportedCapabilities = []capability.Capability{
capability.ThinPack,
}
}

repo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{
URL: repoURL,
Tags: git.AllTags,
Expand Down
12 changes: 12 additions & 0 deletions cyclops-ctrl/internal/template/gitproviders/azure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gitproviders

import "net/url"

func IsAzureRepo(repoURL string) bool {
host, err := url.Parse(repoURL)
if err != nil {
return false
}

return host.Host == "dev.azure.com"
}

0 comments on commit 958a896

Please sign in to comment.