Skip to content

Commit

Permalink
Merge pull request #1178 from merico-dev/refactor-github-action
Browse files Browse the repository at this point in the history
refactor: pluginstaller scm related info
  • Loading branch information
aFlyBird0 authored Oct 17, 2022
2 parents 2f228d3 + d51c079 commit bfc8d02
Show file tree
Hide file tree
Showing 62 changed files with 1,335 additions and 763 deletions.
3 changes: 2 additions & 1 deletion internal/pkg/plugin/gitlabcedocker/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
dockerInstaller "github.com/devstream-io/devstream/internal/pkg/plugininstaller/docker"
"github.com/devstream-io/devstream/pkg/util/log"
"github.com/devstream-io/devstream/pkg/util/types"
)

func Create(options map[string]interface{}) (map[string]interface{}, error) {
Expand All @@ -29,7 +30,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
}

// 3. execute installer get status and error
rawOptions, err := buildDockerOptions(opts).Encode()
rawOptions, err := types.EncodeStruct(buildDockerOptions(opts))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/plugin/gitlabcedocker/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitlabcedocker
import (
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
dockerInstaller "github.com/devstream-io/devstream/internal/pkg/plugininstaller/docker"
"github.com/devstream-io/devstream/pkg/util/types"
)

func Delete(options map[string]interface{}) (bool, error) {
Expand All @@ -23,7 +24,7 @@ func Delete(options map[string]interface{}) (bool, error) {
}

// 3. delete and get status
rawOptions, err := buildDockerOptions(opts).Encode()
rawOptions, err := types.EncodeStruct(buildDockerOptions(opts))
if err != nil {
return false, err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/plugin/gitlabcedocker/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
dockerInstaller "github.com/devstream-io/devstream/internal/pkg/plugininstaller/docker"
"github.com/devstream-io/devstream/pkg/util/log"
"github.com/devstream-io/devstream/pkg/util/types"
)

func Read(options map[string]interface{}) (map[string]interface{}, error) {
Expand All @@ -22,7 +23,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {
}

// 3. get status
rawOptions, err := buildDockerOptions(opts).Encode()
rawOptions, err := types.EncodeStruct(buildDockerOptions(opts))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/plugin/gitlabcedocker/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {
}

// 3. update and get status
rawOptions, err := buildDockerOptions(opts).Encode()
rawOptions, err := types.EncodeStruct(buildDockerOptions(opts))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/plugin/gitlabci/gilabci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package gitlabci

import (
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/ci"
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
"github.com/devstream-io/devstream/pkg/util/scm"
)

var DefaultCIOptions = &ci.Options{
CIConfig: &ci.CIConfig{
Type: "gitlab",
},
ProjectRepo: &common.Repo{
ProjectRepo: &scm.Repo{
RepoType: "gitlab",
},
}
3 changes: 2 additions & 1 deletion internal/pkg/plugin/gitlabci/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/ci"
"github.com/devstream-io/devstream/pkg/util/scm/gitlab"
"github.com/devstream-io/devstream/pkg/util/types"
)

func setCIContent(options plugininstaller.RawOptions) (plugininstaller.RawOptions, error) {
Expand All @@ -26,5 +27,5 @@ func setCIContent(options plugininstaller.RawOptions) (plugininstaller.RawOption
}
ciConfig.SetContent(ciContent)
opts.CIConfig = ciConfig
return opts.Encode()
return types.EncodeStruct(opts)
}
2 changes: 1 addition & 1 deletion internal/pkg/plugin/jenkinspipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
ExecuteOperations: plugininstaller.ExecuteOperations{
jenkins.PreInstall,
jenkins.CreateOrUpdateJob,
jenkins.ConfigRepo,
jenkins.CreateRepoWebhook,
ci.PushCIFiles,
},
GetStateOperation: jenkins.GetStatus,
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/plugin/reposcaffolding/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
operator := &plugininstaller.Operator{
PreExecuteOperations: plugininstaller.PreExecuteOperations{
reposcaffolding.Validate,
reposcaffolding.SetDefaultTemplateRepo,
},
ExecuteOperations: plugininstaller.ExecuteOperations{
reposcaffolding.InstallRepo,
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/plugin/reposcaffolding/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func Delete(options map[string]interface{}) (bool, error) {
operator := &plugininstaller.Operator{
PreExecuteOperations: plugininstaller.PreExecuteOperations{
reposcaffolding.Validate,
reposcaffolding.SetDefaultTemplateRepo,
},
ExecuteOperations: plugininstaller.ExecuteOperations{
reposcaffolding.DeleteRepo,
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/plugin/reposcaffolding/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {
operator := &plugininstaller.Operator{
PreExecuteOperations: plugininstaller.PreExecuteOperations{
reposcaffolding.Validate,
reposcaffolding.SetDefaultTemplateRepo,
},
GetStateOperation: reposcaffolding.GetDynamicState,
}
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/plugin/reposcaffolding/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {
operator := &plugininstaller.Operator{
PreExecuteOperations: plugininstaller.PreExecuteOperations{
reposcaffolding.Validate,
reposcaffolding.SetDefaultTemplateRepo,
},
ExecuteOperations: plugininstaller.ExecuteOperations{
reposcaffolding.DeleteRepo,
Expand Down
16 changes: 4 additions & 12 deletions internal/pkg/plugininstaller/ci/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"github.com/mitchellh/mapstructure"

"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
"github.com/devstream-io/devstream/pkg/util/scm"
"github.com/devstream-io/devstream/pkg/util/types"
)

type Options struct {
CIConfig *CIConfig `mapstructure:"ci" validate:"required"`
ProjectRepo *common.Repo `mapstructure:"projectRepo" validate:"required"`
CIConfig *CIConfig `mapstructure:"ci" validate:"required"`
ProjectRepo *scm.Repo `mapstructure:"projectRepo" validate:"required"`
}

func NewOptions(options plugininstaller.RawOptions) (*Options, error) {
Expand All @@ -22,7 +22,7 @@ func NewOptions(options plugininstaller.RawOptions) (*Options, error) {
}

// FillDefaultValue config options default values by input defaultOptions
func (opts *Options) FillDefaultValue(defaultOptions *Options) {
func (opts *Options) fillDefaultValue(defaultOptions *Options) {
if opts.CIConfig == nil {
opts.CIConfig = defaultOptions.CIConfig
} else {
Expand All @@ -34,11 +34,3 @@ func (opts *Options) FillDefaultValue(defaultOptions *Options) {
types.FillStructDefaultValue(opts.ProjectRepo, defaultOptions.ProjectRepo)
}
}

func (opts *Options) Encode() (map[string]interface{}, error) {
var options map[string]interface{}
if err := mapstructure.Decode(opts, &options); err != nil {
return nil, err
}
return options, nil
}
19 changes: 6 additions & 13 deletions internal/pkg/plugininstaller/ci/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/ci/server"
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
"github.com/devstream-io/devstream/pkg/util/scm"
)

var _ = Describe("Options struct", func() {
Expand All @@ -20,7 +20,7 @@ var _ = Describe("Options struct", func() {
Type: "github",
ConfigLocation: "http://www.test.com",
}
defaultRepo := &common.Repo{
defaultRepo := &scm.Repo{
Owner: "test",
Repo: "test_repo",
Branch: "test_branch",
Expand Down Expand Up @@ -49,10 +49,10 @@ var _ = Describe("Options struct", func() {
})
})

Context("FillDefaultValue method", func() {
Context("fillDefaultValue method", func() {
When("ci config and repo are all empty", func() {
It("should set default value", func() {
opts.FillDefaultValue(defaultOpts)
opts.fillDefaultValue(defaultOpts)
Expect(opts.CIConfig).ShouldNot(BeNil())
Expect(opts.ProjectRepo).ShouldNot(BeNil())
Expect(opts.CIConfig.ConfigLocation).Should(Equal("http://www.test.com"))
Expand All @@ -64,12 +64,12 @@ var _ = Describe("Options struct", func() {
opts.CIConfig = &CIConfig{
ConfigLocation: "http://exist.com",
}
opts.ProjectRepo = &common.Repo{
opts.ProjectRepo = &scm.Repo{
Branch: "new_branch",
}
})
It("should update empty value", func() {
opts.FillDefaultValue(defaultOpts)
opts.fillDefaultValue(defaultOpts)
Expect(opts.CIConfig).ShouldNot(BeNil())
Expect(opts.ProjectRepo).ShouldNot(BeNil())
Expect(opts.CIConfig.ConfigLocation).Should(Equal("http://exist.com"))
Expand All @@ -79,11 +79,4 @@ var _ = Describe("Options struct", func() {
})
})
})

Context("Encode method", func() {
It("should return map", func() {
_, err := opts.Encode()
Expect(err).Error().ShouldNot(HaveOccurred())
})
})
})
5 changes: 3 additions & 2 deletions internal/pkg/plugininstaller/ci/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ci

import (
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
"github.com/devstream-io/devstream/pkg/util/types"
"github.com/devstream-io/devstream/pkg/util/validator"
)

Expand All @@ -25,7 +26,7 @@ func SetDefaultConfig(defaultConfig *Options) plugininstaller.MutableOperation {
if err != nil {
return nil, err
}
opts.FillDefaultValue(defaultConfig)
return opts.Encode()
opts.fillDefaultValue(defaultConfig)
return types.EncodeStruct(opts)
}
}
4 changes: 2 additions & 2 deletions internal/pkg/plugininstaller/ci/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
. "github.com/onsi/gomega"

"github.com/devstream-io/devstream/internal/pkg/plugininstaller/ci"
"github.com/devstream-io/devstream/internal/pkg/plugininstaller/common"
"github.com/devstream-io/devstream/pkg/util/scm"
)

var _ = Describe("Validate func", func() {
Expand Down Expand Up @@ -75,7 +75,7 @@ var _ = Describe("SetDefaultConfig func", func() {
Type: "github",
ConfigLocation: "http://www.test.com",
}
defaultRepo := &common.Repo{
defaultRepo := &scm.Repo{
Owner: "test",
Repo: "test_repo",
Branch: "test_branch",
Expand Down
Loading

0 comments on commit bfc8d02

Please sign in to comment.