-
Notifications
You must be signed in to change notification settings - Fork 51
/
pipelinecatalogs.go
36 lines (33 loc) · 1.26 KB
/
pipelinecatalogs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package pipelinecatalogs
import (
"path/filepath"
"github.com/jenkins-x-plugins/jx-gitops/pkg/apis/gitops/v1alpha1"
"github.com/jenkins-x/jx-helpers/v3/pkg/files"
"github.com/jenkins-x/jx-helpers/v3/pkg/yamls"
"github.com/pkg/errors"
)
// LoadPipelineCatalogs loads the pipeline catalogs and the file name for the given directory
func LoadPipelineCatalogs(dir string) (*v1alpha1.PipelineCatalog, string, error) {
fileName := filepath.Join(dir, "extensions", v1alpha1.PipelineCatalogFileName)
exists, err := files.FileExists(fileName)
if err != nil {
return nil, fileName, errors.Wrapf(err, "failed to check if file exists %s", fileName)
}
pipelineCatalog := &v1alpha1.PipelineCatalog{}
if exists {
err = yamls.LoadFile(fileName, pipelineCatalog)
if err != nil {
return nil, fileName, errors.Wrapf(err, "failed to load PipelineCatalog file %s", fileName)
}
if len(pipelineCatalog.Spec.Repositories) == 0 {
// lets add a default repository
pipelineCatalog.Spec.Repositories = append(pipelineCatalog.Spec.Repositories, v1alpha1.PipelineCatalogSource{
ID: "jx3-pipeline-catalog",
Label: "JX3 Pipeline Catalog",
GitURL: "https://github.com/jenkins-x/jx3-pipeline-catalog",
GitRef: "master",
})
}
}
return pipelineCatalog, fileName, nil
}