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

support azure repos #664

Merged
merged 2 commits into from
Oct 30, 2024
Merged
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
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"
}
Loading