Skip to content

Commit 442dcad

Browse files
committed
refactor: pluginstaller scm related info
Signed-off-by: Meng JiaFeng <jiafeng.meng@merico.dev>
1 parent 845e66d commit 442dcad

53 files changed

Lines changed: 1324 additions & 704 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/pkg/plugin/gitlabci/gilabci.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package gitlabci
22

33
import (
44
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/ci"
5-
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
5+
"github.com/devstream-io/devstream/pkg/util/scm"
66
)
77

88
var DefaultCIOptions = &ci.Options{
99
CIConfig: &ci.CIConfig{
1010
Type: "gitlab",
1111
},
12-
ProjectRepo: &common.Repo{
12+
ProjectRepo: &scm.Repo{
1313
RepoType: "gitlab",
1414
},
1515
}

internal/pkg/plugin/gitlabci/golang/golang.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
55
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/ci"
66
"github.com/devstream-io/devstream/pkg/util/scm/gitlab"
7+
"github.com/devstream-io/devstream/pkg/util/types"
78
)
89

910
func setCIContent(options plugininstaller.RawOptions) (plugininstaller.RawOptions, error) {
@@ -26,5 +27,5 @@ func setCIContent(options plugininstaller.RawOptions) (plugininstaller.RawOption
2627
}
2728
ciConfig.SetContent(ciContent)
2829
opts.CIConfig = ciConfig
29-
return opts.Encode()
30+
return types.EncodeStruct(opts)
3031
}

internal/pkg/plugin/jenkinspipeline/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
1717
ExecuteOperations: plugininstaller.ExecuteOperations{
1818
jenkins.PreInstall,
1919
jenkins.CreateOrUpdateJob,
20-
jenkins.ConfigRepo,
20+
jenkins.CreateRepoWebhook,
2121
ci.PushCIFiles,
2222
},
2323
GetStateOperation: jenkins.GetStatus,

internal/pkg/plugin/reposcaffolding/create.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
1111
operator := &plugininstaller.Operator{
1212
PreExecuteOperations: plugininstaller.PreExecuteOperations{
1313
reposcaffolding.Validate,
14-
reposcaffolding.SetDefaultTemplateRepo,
1514
},
1615
ExecuteOperations: plugininstaller.ExecuteOperations{
1716
reposcaffolding.InstallRepo,

internal/pkg/plugin/reposcaffolding/delete.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ func Delete(options map[string]interface{}) (bool, error) {
1010
operator := &plugininstaller.Operator{
1111
PreExecuteOperations: plugininstaller.PreExecuteOperations{
1212
reposcaffolding.Validate,
13-
reposcaffolding.SetDefaultTemplateRepo,
1413
},
1514
ExecuteOperations: plugininstaller.ExecuteOperations{
1615
reposcaffolding.DeleteRepo,

internal/pkg/plugin/reposcaffolding/read.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {
1010
operator := &plugininstaller.Operator{
1111
PreExecuteOperations: plugininstaller.PreExecuteOperations{
1212
reposcaffolding.Validate,
13-
reposcaffolding.SetDefaultTemplateRepo,
1413
},
1514
GetStateOperation: reposcaffolding.GetDynamicState,
1615
}

internal/pkg/plugin/reposcaffolding/update.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {
1010
operator := &plugininstaller.Operator{
1111
PreExecuteOperations: plugininstaller.PreExecuteOperations{
1212
reposcaffolding.Validate,
13-
reposcaffolding.SetDefaultTemplateRepo,
1413
},
1514
ExecuteOperations: plugininstaller.ExecuteOperations{
1615
reposcaffolding.DeleteRepo,

internal/pkg/plugininstaller/ci/option.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"github.com/mitchellh/mapstructure"
55

66
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
7-
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
7+
"github.com/devstream-io/devstream/pkg/util/scm"
88
"github.com/devstream-io/devstream/pkg/util/types"
99
)
1010

1111
type Options struct {
12-
CIConfig *CIConfig `mapstructure:"ci" validate:"required"`
13-
ProjectRepo *common.Repo `mapstructure:"projectRepo" validate:"required"`
12+
CIConfig *CIConfig `mapstructure:"ci" validate:"required"`
13+
ProjectRepo *scm.Repo `mapstructure:"projectRepo" validate:"required"`
1414
}
1515

1616
func NewOptions(options plugininstaller.RawOptions) (*Options, error) {
@@ -22,7 +22,7 @@ func NewOptions(options plugininstaller.RawOptions) (*Options, error) {
2222
}
2323

2424
// FillDefaultValue config options default values by input defaultOptions
25-
func (opts *Options) FillDefaultValue(defaultOptions *Options) {
25+
func (opts *Options) fillDefaultValue(defaultOptions *Options) {
2626
if opts.CIConfig == nil {
2727
opts.CIConfig = defaultOptions.CIConfig
2828
} else {
@@ -34,11 +34,3 @@ func (opts *Options) FillDefaultValue(defaultOptions *Options) {
3434
types.FillStructDefaultValue(opts.ProjectRepo, defaultOptions.ProjectRepo)
3535
}
3636
}
37-
38-
func (opts *Options) Encode() (map[string]interface{}, error) {
39-
var options map[string]interface{}
40-
if err := mapstructure.Decode(opts, &options); err != nil {
41-
return nil, err
42-
}
43-
return options, nil
44-
}

internal/pkg/plugininstaller/ci/option_test.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
88
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/ci/server"
9-
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
9+
"github.com/devstream-io/devstream/pkg/util/scm"
1010
)
1111

1212
var _ = Describe("Options struct", func() {
@@ -20,7 +20,7 @@ var _ = Describe("Options struct", func() {
2020
Type: "github",
2121
ConfigLocation: "http://www.test.com",
2222
}
23-
defaultRepo := &common.Repo{
23+
defaultRepo := &scm.Repo{
2424
Owner: "test",
2525
Repo: "test_repo",
2626
Branch: "test_branch",
@@ -49,10 +49,10 @@ var _ = Describe("Options struct", func() {
4949
})
5050
})
5151

52-
Context("FillDefaultValue method", func() {
52+
Context("fillDefaultValue method", func() {
5353
When("ci config and repo are all empty", func() {
5454
It("should set default value", func() {
55-
opts.FillDefaultValue(defaultOpts)
55+
opts.fillDefaultValue(defaultOpts)
5656
Expect(opts.CIConfig).ShouldNot(BeNil())
5757
Expect(opts.ProjectRepo).ShouldNot(BeNil())
5858
Expect(opts.CIConfig.ConfigLocation).Should(Equal("http://www.test.com"))
@@ -64,12 +64,12 @@ var _ = Describe("Options struct", func() {
6464
opts.CIConfig = &CIConfig{
6565
ConfigLocation: "http://exist.com",
6666
}
67-
opts.ProjectRepo = &common.Repo{
67+
opts.ProjectRepo = &scm.Repo{
6868
Branch: "new_branch",
6969
}
7070
})
7171
It("should update empty value", func() {
72-
opts.FillDefaultValue(defaultOpts)
72+
opts.fillDefaultValue(defaultOpts)
7373
Expect(opts.CIConfig).ShouldNot(BeNil())
7474
Expect(opts.ProjectRepo).ShouldNot(BeNil())
7575
Expect(opts.CIConfig.ConfigLocation).Should(Equal("http://exist.com"))
@@ -79,11 +79,4 @@ var _ = Describe("Options struct", func() {
7979
})
8080
})
8181
})
82-
83-
Context("Encode method", func() {
84-
It("should return map", func() {
85-
_, err := opts.Encode()
86-
Expect(err).Error().ShouldNot(HaveOccurred())
87-
})
88-
})
8982
})

internal/pkg/plugininstaller/ci/validate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ci
22

33
import (
44
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
5+
"github.com/devstream-io/devstream/pkg/util/types"
56
"github.com/devstream-io/devstream/pkg/util/validator"
67
)
78

@@ -25,7 +26,7 @@ func SetDefaultConfig(defaultConfig *Options) plugininstaller.MutableOperation {
2526
if err != nil {
2627
return nil, err
2728
}
28-
opts.FillDefaultValue(defaultConfig)
29-
return opts.Encode()
29+
opts.fillDefaultValue(defaultConfig)
30+
return types.EncodeStruct(opts)
3031
}
3132
}

0 commit comments

Comments
 (0)