(repoURL, path, commit, resolvedVersion string)
| 34 | ) |
| 35 | |
| 36 | func (r Repo) LoadTemplate(repoURL, path, commit, resolvedVersion string) (*models.Template, error) { |
| 37 | creds, err := r.credResolver.RepoAuthCredentials(repoURL) |
| 38 | if err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | |
| 42 | commitSHA := resolvedVersion |
| 43 | if len(commitSHA) == 0 { |
| 44 | ref, err := resolveRef(repoURL, commit, creds) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | |
| 49 | commitSHA = ref |
| 50 | } |
| 51 | |
| 52 | cached, ok := r.cache.GetTemplate(repoURL, path, commitSHA, string(cyclopsv1alpha1.TemplateSourceTypeGit)) |
| 53 | if ok { |
| 54 | return cached, nil |
| 55 | } |
| 56 | |
| 57 | if gitproviders2.IsGitHubSource(repoURL) { |
| 58 | ghTemplate, err := r.mapGitHubRepoTemplate(repoURL, path, commitSHA, creds) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | |
| 63 | ghTemplate.Version = commit |
| 64 | ghTemplate.ResolvedVersion = commitSHA |
| 65 | |
| 66 | r.cache.SetTemplate(repoURL, path, commitSHA, string(cyclopsv1alpha1.TemplateSourceTypeGit), ghTemplate) |
| 67 | |
| 68 | return ghTemplate, nil |
| 69 | } |
| 70 | |
| 71 | fs, err := clone(repoURL, commit, creds) |
| 72 | if err != nil { |
| 73 | return nil, err |
| 74 | } |
| 75 | |
| 76 | // region read files |
| 77 | filesFs, err := fs.Chroot(path) |
| 78 | if err != nil { |
| 79 | return nil, errors.Wrap(err, "could not find 'templates' dir; it should be placed in the repo/path you provided; make sure 'templates' directory exists") |
| 80 | } |
| 81 | |
| 82 | files, err := readFiles("", filesFs) |
| 83 | if err != nil { |
| 84 | return nil, errors.Wrap(err, "failed to read template files") |
| 85 | } |
| 86 | // endregion |
| 87 | |
| 88 | if len(files) == 0 { |
| 89 | return nil, errors.Errorf("no files found in repo %v on path %v; make sure the repo, path and version are correct", repoURL, path) |
| 90 | } |
| 91 | |
| 92 | // region map files to template |
| 93 | metadataBytes := []byte{} |
no test coverage detected