Skip to content

Commit fd68e14

Browse files
authored
Merge pull request #1323 from merico-dev/refactor-scm-git-options
refactor: use git.RepoInfo for all git repo related config
2 parents 13a1cf8 + 896551d commit fd68e14

Some content is hidden

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

44 files changed

+700
-944
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ I am happy to tell you that we have, and we are constantly adding more possible
9191
so you are more than welcome to tell us what combinations you expect.
9292

9393
- [GitOps Toolchain](https://docs.devstream.io/en/latest/best-practices/gitops/)
94-
- [GitLab, Jenkins and Harbor On Premise Toolchain (Chinese only for now)](https://docs.devstream.io/en/latest/best-practices/gitlab-jenkins-harbor.zh/)
94+
- [GitLab, Jenkins and Harbor On Premise Toolchain (Chinese only for now)](https://docs.devstream.io/en/latest/best-practices/gitlab-jenkins-harbor-java-springboot.zh/)
9595

9696
## Supported DevOps Tools
9797

README_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ DevStream支持许多工具的管理。你可以灵活地结合一些工具来
9292
我们非常欢迎你告诉我们你期望的组合。
9393

9494
- [GitOps工具链](https://docs.devstream.io/en/latest/best-practices/gitops.zh/)
95-
- [用 DevStream 搭建 GitLab + Jenkins + Harbor 工具链,管理 Java Spring Boot 项目开发生命周期全流程](https://docs.devstream.io/en/latest/best-practices/gitlab-jenkins-harbor.zh/)
95+
- [用 DevStream 搭建 GitLab + Jenkins + Harbor 工具链,管理 Java Spring Boot 项目开发生命周期全流程](https://docs.devstream.io/en/latest/best-practices/gitlab-jenkins-harbor-java-springboot.zh/)
9696

9797
## 支持的DevOps工具
9898

docs/best-practices/gjh-java-springboot-air-gapped-deployment.zh.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ sh -c "$(curl -fsSL https://download.devstream.io/download.sh)"
3737
curl -o dtm https://download.devstream.io/v0.10.2/dtm-linux-amd64
3838
```
3939

40-
注意:这里的版本、系统类型、CPU 架构等信息需要灵活调整。比如你用的是 arm64 的服务器,这里就需要将命令改成:
41-
42-
```shell
43-
curl -o dtm https://download.devstream.io/v0.10.2/dtm-linux-arm64
44-
```
40+
注意:这里的版本、系统类型、CPU 架构等信息需要灵活调整。
4541

4642
等 dtm 下载到你的 PC 后,你需要通过内网将其传输到某一台内部服务器上,移入包含在"$PATH"的目录里并赋予其可执行权限,比如在 Linux 上你可以执行如下命令完成这些操作:
4743

docs/plugins/repo-scaffolding.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ tools:
108108
destinationRepo:
109109
owner: test_owner
110110
org: ""
111-
repo: dtm-test-golang
111+
name: dtm-test-golang
112112
branch: main
113-
repoType: github
113+
scmType: github
114114
sourceRepo:
115115
org: devstream-io
116-
repo: dtm-scaffolding-golang
117-
repoType: github
116+
name: dtm-scaffolding-golang
117+
scmType: github
118118
vars:
119119
imageRepo: dtm-test/golang-repo
120120
```
@@ -131,13 +131,13 @@ tools:
131131
destinationRepo:
132132
owner: test_owner
133133
org: ""
134-
repo: dtm-test-golang-cli
134+
name: dtm-test-golang-cli
135135
branch: main
136-
repoType: github
136+
scmType: github
137137
sourceRepo:
138138
org: devstream-io
139-
repo: dtm-scaffolding-golang-cli
140-
repoType: github
139+
name: dtm-scaffolding-golang-cli
140+
scmType: github
141141
```
142142

143143
This config will create `dtm-test-golang-cli` repo for user test_owner in GitHub.
@@ -152,15 +152,15 @@ tools:
152152
destinationRepo:
153153
owner: test_owner
154154
org: ""
155-
repo: dtm-test-java
155+
name: dtm-test-java
156156
branch: main
157157
baseUrl: 127.0.0.1:30001
158158
visibility: public
159-
repoType: gitlab
159+
scmType: gitlab
160160
sourceRepo:
161161
org: spring-guides
162-
repo: gs-spring-boot
163-
repoType: github
162+
name: gs-spring-boot
163+
scmType: github
164164
```
165165

166166
this config will create `dtm-test-java` repo for user test_owner in GitHub.

docs/plugins/repo-scaffolding.zh.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ tools:
105105
destinationRepo:
106106
owner: test_owner
107107
org: ""
108-
repo: dtm-test-golang
108+
name: dtm-test-golang
109109
branch: main
110-
repoType: github
110+
scmType: github
111111
sourceRepo:
112112
org: devstream-io
113-
repo: dtm-scaffolding-golang
114-
repoType: github
113+
name: dtm-scaffolding-golang
114+
scmType: github
115115
vars:
116116
ImageRepo: dtm-test/golang-repo
117117
```
@@ -128,13 +128,13 @@ tools:
128128
destinationRepo:
129129
owner: test_owner
130130
org: ""
131-
repo: dtm-test-golang-cli
131+
name: dtm-test-golang-cli
132132
branch: main
133-
repoType: github
133+
scmType: github
134134
sourceRepo:
135135
org: devstream-io
136-
repo: dtm-scaffolding-golang-cli
137-
repoType: github
136+
name: dtm-scaffolding-golang-cli
137+
scmType: github
138138
```
139139

140140
这个配置在 GitHub 为用于 test_owner 创建 `dtm-test-golang-cli` 仓库,它的生成是基于 `devstream-io/dtm-scaffolding-golang-cli` 官方 Golang CLI 脚手架仓库。
@@ -149,15 +149,15 @@ tools:
149149
destinationRepo:
150150
owner: test_owner
151151
org: ""
152-
repo: dtm-test-java
152+
name: dtm-test-java
153153
branch: main
154154
baseUrl: 127.0.0.1:30001
155155
visibility: public
156-
repoType: gitlab
156+
scmType: gitlab
157157
sourceRepo:
158158
org: spring-guides
159-
repo: gs-spring-boot
160-
repoType: github
159+
name: gs-spring-boot
160+
scmType: github
161161
```
162162

163163
这个配置会在 GitLab 为用户 test_owner 创建 `dtm-test-java` 仓库,使用的是 Spring 官方的 `spring-guides/gs-spring-boot` 仓库。

internal/pkg/configmanager/app.go

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/devstream-io/devstream/pkg/util/log"
7-
"github.com/devstream-io/devstream/pkg/util/scm"
87
"github.com/devstream-io/devstream/pkg/util/scm/git"
98
)
109

@@ -13,23 +12,17 @@ const (
1312
)
1413

1514
type repoTemplate struct {
16-
*scm.SCMInfo `yaml:",inline"`
17-
Vars RawOptions `yaml:"vars"`
15+
*git.RepoInfo `yaml:",inline"`
16+
Vars RawOptions `yaml:"vars"`
1817
}
1918

2019
type app struct {
2120
Name string `yaml:"name" mapstructure:"name"`
2221
Spec *appSpec `yaml:"spec" mapstructure:"spec"`
23-
Repo *scm.SCMInfo `yaml:"repo" mapstructure:"repo"`
22+
Repo *git.RepoInfo `yaml:"repo" mapstructure:"repo"`
2423
RepoTemplate *repoTemplate `yaml:"repoTemplate" mapstructure:"repoTemplate"`
2524
CIRawConfigs []pipelineRaw `yaml:"ci" mapstructure:"ci"`
2625
CDRawConfigs []pipelineRaw `yaml:"cd" mapstructure:"cd"`
27-
28-
// these two variables is used internal for convince
29-
// repoInfo is generated from Repo field with setDefault method
30-
repoInfo *git.RepoInfo `yaml:"-" mapstructure:"-"`
31-
// repoTemplateInfo is generated from RepoTemplate field with setDefault method
32-
repoTemplateInfo *git.RepoInfo `yaml:"-" mapstructure:"-"`
3326
}
3427

3528
func (a *app) getTools(vars map[string]any, templateMap map[string]string) (Tools, error) {
@@ -54,7 +47,7 @@ func (a *app) getTools(vars map[string]any, templateMap map[string]string) (Tool
5447
return tools, nil
5548
}
5649

57-
// generateAppPipelineTool generate ci/cd tools from app config
50+
// generateCICDTools generate ci/cd tools from app config
5851
func (a *app) generateCICDTools(templateMap map[string]string, appVars map[string]any) (Tools, error) {
5952
allPipelineRaw := append(a.CIRawConfigs, a.CDRawConfigs...)
6053
var tools Tools
@@ -78,16 +71,16 @@ func (a *app) generateCICDTools(templateMap map[string]string, appVars map[strin
7871

7972
// generateRepoTemplateTool will use repo-scaffolding plugin for app
8073
func (a *app) generateRepoTemplateTool() *Tool {
81-
if a.repoTemplateInfo != nil {
74+
if a.RepoTemplate != nil {
8275
templateVars := make(RawOptions)
8376
// templateRepo doesn't need auth info
8477
if a.RepoTemplate.Vars == nil {
8578
templateVars = make(RawOptions)
8679
}
8780
return newTool(
8881
repoScaffoldingPluginName, a.Name, RawOptions{
89-
"destinationRepo": RawOptions(a.repoInfo.Encode()),
90-
"sourceRepo": RawOptions(a.repoTemplateInfo.Encode()),
82+
"destinationRepo": RawOptions(a.Repo.Encode()),
83+
"sourceRepo": RawOptions(a.RepoTemplate.Encode()),
9184
"vars": templateVars,
9285
},
9386
)
@@ -100,22 +93,8 @@ func (a *app) setDefault() error {
10093
if a.Repo == nil {
10194
return fmt.Errorf("configmanager[app] is invalid, repo field must be configured")
10295
}
103-
if a.Repo.Name == "" {
104-
a.Repo.Name = a.Name
105-
}
106-
appRepo, err := a.Repo.BuildRepoInfo()
107-
if err != nil {
108-
return fmt.Errorf("configmanager[app] parse repo failed: %w", err)
109-
}
110-
a.repoInfo = appRepo
111-
if a.RepoTemplate != nil {
112-
// templateRepo doesn't need auth info
113-
templateRepo, err := a.RepoTemplate.BuildRepoInfo()
114-
if err != nil {
115-
return fmt.Errorf("configmanager[app] parse repoTemplate failed: %w", err)
116-
}
117-
templateRepo.NeedAuth = false
118-
a.repoTemplateInfo = templateRepo
96+
if a.Repo.Repo == "" {
97+
a.Repo.Repo = a.Name
11998
}
12099
return nil
121100
}
@@ -133,9 +112,8 @@ func (a *app) getRepoTemplateDependants() []string {
133112
// newPipelineGlobalOptionFromApp generate pipeline options used for pipeline option configuration
134113
func (a *app) newPipelineGlobalOptionFromApp() *pipelineGlobalOption {
135114
return &pipelineGlobalOption{
136-
RepoInfo: a.repoInfo,
137-
AppSpec: a.Spec,
138-
Scm: a.Repo,
139-
AppName: a.Name,
115+
Repo: a.Repo,
116+
AppSpec: a.Spec,
117+
AppName: a.Name,
140118
}
141119
}

internal/pkg/configmanager/app_test.go

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
. "github.com/onsi/ginkgo/v2"
55
. "github.com/onsi/gomega"
66

7-
"github.com/devstream-io/devstream/pkg/util/scm"
7+
"github.com/devstream-io/devstream/pkg/util/scm/git"
88
)
99

1010
var _ = Describe("app struct", func() {
@@ -33,7 +33,7 @@ var _ = Describe("app struct", func() {
3333
When("ci/cd template is not valid", func() {
3434
BeforeEach(func() {
3535
a = &app{
36-
Repo: &scm.SCMInfo{
36+
Repo: &git.RepoInfo{
3737
CloneURL: "http://test.com/test/test_app",
3838
},
3939
CIRawConfigs: []pipelineRaw{
@@ -54,7 +54,7 @@ var _ = Describe("app struct", func() {
5454
BeforeEach(func() {
5555
a = &app{
5656
Name: appName,
57-
Repo: &scm.SCMInfo{
57+
Repo: &git.RepoInfo{
5858
CloneURL: "http://test.com/test/test_app",
5959
},
6060
}
@@ -65,49 +65,13 @@ var _ = Describe("app struct", func() {
6565
Expect(len(tools)).Should(Equal(0))
6666
})
6767
})
68-
When("repo url is not valid", func() {
69-
BeforeEach(func() {
70-
a = &app{
71-
Name: appName,
72-
Repo: &scm.SCMInfo{
73-
CloneURL: "not_valid_url",
74-
},
75-
}
76-
})
77-
It("should return empty tools", func() {
78-
_, err := a.getTools(vars, templateMap)
79-
Expect(err).Should(HaveOccurred())
80-
Expect(err.Error()).Should(ContainSubstring("configmanager[app] parse repo failed"))
81-
})
82-
})
83-
When("template repo url is not valid", func() {
84-
BeforeEach(func() {
85-
a = &app{
86-
Name: appName,
87-
RepoTemplate: &repoTemplate{
88-
SCMInfo: &scm.SCMInfo{
89-
CloneURL: "not_valid_url",
90-
},
91-
},
92-
Repo: &scm.SCMInfo{
93-
CloneURL: "http://test.com/test/test_app",
94-
},
95-
}
96-
})
97-
It("should return empty tools", func() {
98-
_, err := a.getTools(vars, templateMap)
99-
Expect(err).Should(HaveOccurred())
100-
Expect(err.Error()).Should(ContainSubstring("configmanager[app] parse repoTemplate failed"))
101-
})
102-
})
103-
10468
})
10569

10670
Context("generateCICDTools method", func() {
10771
When("template type not exist", func() {
10872
BeforeEach(func() {
10973
a = &app{
110-
Repo: &scm.SCMInfo{
74+
Repo: &git.RepoInfo{
11175
CloneURL: "http://test.com/test/test_app",
11276
},
11377
CIRawConfigs: []pipelineRaw{

internal/pkg/configmanager/configmanager_test.go

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

77
. "github.com/onsi/ginkgo/v2"
88
. "github.com/onsi/gomega"
9+
10+
"github.com/devstream-io/devstream/pkg/util/scm/git"
911
)
1012

1113
var _ = Describe("Manager struct", func() {
@@ -32,7 +34,6 @@ apps:
3234
repo:
3335
scmType: github
3436
owner: devstream-io
35-
org: devstream-io # choose between owner and org
3637
url: github.com/devstream-io/service-a # optional,if url is specified,we can infer scm/owner/org/name from url
3738
apiURL: gitlab.com/some/path/to/your/api # optional, if you want to create a repo from repo template
3839
# if repoTemplate is not empty,we could help user to create repo from scaffoldingRepo
@@ -148,10 +149,9 @@ pipelineTemplates:
148149
"scm": RawOptions{
149150
"apiURL": "gitlab.com/some/path/to/your/api",
150151
"owner": "devstream-io",
151-
"org": "devstream-io",
152152
"name": "service-a",
153153
"scmType": "github",
154-
"url": "https://github.com/devstream-io/service-a",
154+
"url": git.ScmURL("github.com/devstream-io/service-a"),
155155
},
156156
},
157157
}
@@ -191,19 +191,18 @@ pipelineTemplates:
191191
Options: RawOptions{
192192
"instanceID": "service-a",
193193
"destinationRepo": RawOptions{
194-
"needAuth": true,
195-
"org": "devstream-io",
196-
"repo": "service-a",
197-
"branch": "main",
198-
"repoType": "github",
199-
"url": "github.com/devstream-io/service-a",
194+
"owner": "devstream-io",
195+
"name": "service-a",
196+
"scmType": "github",
197+
"apiURL": "gitlab.com/some/path/to/your/api",
198+
"url": git.ScmURL("github.com/devstream-io/service-a"),
200199
},
201200
"sourceRepo": RawOptions{
202-
"repoType": "github",
203-
"url": "github.com/devstream-io/dtm-scaffolding-golang",
204-
"org": "devstream-io",
205-
"repo": "dtm-scaffolding-golang",
206-
"branch": "main",
201+
"scmType": "github",
202+
"url": git.ScmURL("github.com/devstream-io/dtm-scaffolding-golang"),
203+
"owner": "devstream-io",
204+
"name": "dtm-scaffolding-golang",
205+
"org": "devstream-io",
207206
},
208207
"vars": RawOptions{},
209208
},

0 commit comments

Comments
 (0)