-
Notifications
You must be signed in to change notification settings - Fork 30
/
enable.go
105 lines (88 loc) · 2.67 KB
/
enable.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package enable
import (
"io"
"strings"
"github.com/jenkins-x/jx-helpers/v3/pkg/gitclient"
"github.com/pkg/errors"
"github.com/jenkins-x-plugins/jx-project/pkg/cmd/importcmd"
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/helper"
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/templates"
"github.com/jenkins-x/lighthouse-client/pkg/triggerconfig"
"github.com/spf13/cobra"
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
)
// Options contains the command line options
type Options struct {
importcmd.ImportOptions
RegenCharts bool
}
var (
cmdLong = templates.LongDesc(`
Enables lighthouse pipelines in the current directory
`)
cmdExample = templates.Examples(`
# Enables lighthouse pipelines in the current dir
jx project enable
`)
)
// Trigger the found trigger configs
type Trigger struct {
Path string
Config *triggerconfig.Config
Names []string
Pipelines map[string]*tektonv1beta1.PipelineRun
}
// NewCmdPipelineEnable creates the command
func NewCmdPipelineEnable() (*cobra.Command, *Options) {
o := &Options{}
o.ImportOptions.NoDevPullRequest = true
o.ImportOptions.DisableStartPipeline = true
o.ImportOptions.DisableStartPipeline = true
o.ImportOptions.IgnoreJenkinsXFile = true
if o.RegenCharts {
o.ImportOptions.PackFilter = func(pack *importcmd.Pack) {
// lets exclude everything from the pack other than lighthouse files
m := map[string]io.ReadCloser{}
for k, v := range pack.Files {
if strings.HasPrefix(k, ".lighthouse") {
m[k] = v
}
}
pack.Charts = nil
pack.Files = m
}
}
cmd := &cobra.Command{
Use: "enable",
Short: "Enables lighthouse pipelines in the current directory",
Long: cmdLong,
Example: cmdExample,
Aliases: []string{"dump"},
Run: func(cmd *cobra.Command, args []string) {
err := o.Run()
helper.CheckErr(err)
},
}
cmd.Flags().BoolVarP(&o.RegenCharts, "charts", "", false, "Should we regen the charts")
cmd.Flags().StringVarP(&o.Dir, "dir", "", ".", "Specify the directory to import")
cmd.Flags().StringVarP(&o.Pack, "pack", "", "", "The name of the pipeline catalog pack to use. If none is specified it will be chosen based on matching the source code languages")
o.BaseOptions.AddBaseFlags(cmd)
o.ScmFactory.AddFlags(cmd)
return cmd, o
}
// Validate verifies settings
func (o *Options) Validate() error {
return nil
}
// Run implements this command
func (o *Options) Run() error {
err := o.ImportOptions.Run()
if err != nil {
return errors.Wrapf(err, "failed to enable lighthouse pipelines")
}
err = gitclient.Add(o.Git(), o.Dir, ".lighthouse")
if err != nil {
return errors.Wrapf(err, "failed to add the .lighthouse dir to git")
}
return nil
}