Skip to content

Commit 93367e1

Browse files
authored
Merge pull request #1389 from merico-dev/refactor-scm-config-use-env
feat: use config field instead of env
2 parents b35405a + 7bd26d0 commit 93367e1

35 files changed

+179
-286
lines changed

examples/apps.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ apps:
1919
framework: django
2020
repo:
2121
url: github.com/[[ GITHUB_USER ]]/myapp1
22+
token: [[ env GITHUB_TOKEN ]]
2223
repoTemplate:
2324
url: github.com/devstream-io/dtm-repo-scaffolding-python-flask
2425
ci:
2526
- type: github-actions
2627
options:
2728
imageRepo:
2829
user: [[ DOCKERHUB_USER ]]
30+
password: [[ env IMAGE_REPO_PASSWORD ]]
2931
cd:
3032
- type: argocdapp
3133
- name: myapp2
@@ -34,12 +36,14 @@ apps:
3436
framework: gin
3537
repo:
3638
url: github.com/[[ GITHUB_USER ]]/myapp2
39+
token: [[ env GITHUB_TOKEN ]]
3740
repoTemplate:
3841
url: github.com/devstream-io/dtm-repo-scaffolding-golang-gin
3942
ci:
4043
- type: github-actions
4144
options:
4245
imageRepo:
4346
user: [[ DOCKERHUB_USER ]]
47+
password: [[ env IMAGE_REPO_PASSWORD ]]
4448
cd:
4549
- type: argocdapp

examples/gitops.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tools:
1717
name: [[ app ]]
1818
branch: main
1919
scmType: github
20+
token: [[ env GITHUB_TOKEN ]]
2021
sourceRepo:
2122
org: devstream-io
2223
name: dtm-repo-scaffolding-python-flask
@@ -29,13 +30,15 @@ tools:
2930
owner: [[ githubUser ]]
3031
name: [[ app ]]
3132
scmType: github
33+
token: [[ env GITHUB_TOKEN ]]
3234
pipeline:
3335
configLocation: https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/github-actions/workflows/main.yml
3436
language:
3537
name: python
3638
framework: flask
3739
imageRepo:
3840
user: [[ dockerUser ]]
41+
password: [[ env IMAGE_REPO_PASSWORD ]]
3942
- name: helm-installer
4043
instanceID: argocd
4144
- name: argocdapp
@@ -52,5 +55,6 @@ tools:
5255
valuefile: values.yaml
5356
path: helm/[[ app ]]
5457
repoURL: ${{repo-scaffolding.myapp.outputs.repoURL}}
58+
token: [[ env GITHUB_TOKEN ]]
5559
imageRepo:
5660
user: [[ dockerUser ]]

examples/quickstart.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tools:
1717
name: go-webapp-devstream-demo
1818
branch: main
1919
scmType: github
20+
token: [[ env GITHUB_TOKEN ]]
2021
sourceRepo:
2122
org: devstream-io
2223
name: dtm-repo-scaffolding-golang-gin
@@ -30,10 +31,12 @@ tools:
3031
name: go-webapp-devstream-demo
3132
branch: main
3233
scmType: github
34+
token: [[ env GITHUB_TOKEN ]]
3335
pipeline:
3436
configLocation: https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/github-actions/workflows/main.yml
3537
language:
3638
name: go
3739
framework: gin
3840
imageRepo:
3941
user: [[ ImageRepoUser ]]
42+
password: [[ env IMAGE_REPO_PASSWORD ]]

internal/pkg/configmanager/pipelineDefault.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func pipelineArgocdAppGenerator(options RawOptions, globalVars *pipelineGlobalOp
8484
if _, repoURLExist := sourceMap["repoURL"]; !repoURLExist {
8585
sourceMap["repoURL"] = globalVars.Repo.GetCloneURL()
8686
sourceMap["repoBranch"] = globalVars.Repo.Branch
87+
sourceMap["token"] = globalVars.Repo.Token
8788
}
8889
options["source"] = sourceMap
8990
} else {
@@ -92,6 +93,7 @@ func pipelineArgocdAppGenerator(options RawOptions, globalVars *pipelineGlobalOp
9293
"path": fmt.Sprintf("helm/%s", globalVars.AppName),
9394
"repoURL": string(globalVars.Repo.GetCloneURL()),
9495
"repoBranch": globalVars.Repo.Branch,
96+
"token": globalVars.Repo.Token,
9597
}
9698
}
9799
// config imageRepo default options

internal/pkg/configmanager/pipelineDefault_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ var _ = Describe("pipelineArgocdAppGenerator func", func() {
9090
"path": "helm/test_app",
9191
"repoURL": "https://scm.test.com",
9292
"repoBranch": "testBranch",
93+
"token": "",
9394
},
9495
"imageRepo": RawOptions{
9596
"owner": "test_user",

internal/pkg/plugin/argocdapp/argocdapp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func pushArgocdConfigFiles(rawOptions configmanager.RawOptions) error {
2525
repoInfo := &git.RepoInfo{
2626
CloneURL: git.ScmURL(opts.Source.RepoURL),
2727
Branch: opts.Source.RepoBranch,
28+
Token: opts.Source.Token,
2829
}
2930
scmClient, err := scm.NewClientWithAuth(repoInfo)
3031
if err != nil {

internal/pkg/plugin/argocdapp/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type source struct {
4747
Path string `mapstructure:"path" validate:"required"`
4848
RepoURL string `mapstructure:"repoURL" validate:"required"`
4949
RepoBranch string `mapstructure:"repoBranch"`
50+
Token string `mapstructure:"token"`
5051
}
5152

5253
// / newOptions create options by raw options

internal/pkg/plugin/gitlabci/options_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ var _ = Describe("action struct", func() {
5454
"ImageRepoDockerSecret": "image-repo-auth",
5555
"RepoType": "gitlab",
5656
"imageRepo": map[string]interface{}{
57-
"url": "exmaple.com",
58-
"user": "test_user",
57+
"url": "exmaple.com",
58+
"user": "test_user",
59+
"password": "",
5960
},
6061
"dingTalk": nilDingTalkConfig,
6162
"DingTalkSecretKey": "DINGTALK_SECURITY_VALUE",

internal/pkg/plugin/installer/ci/ci_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ var _ = Describe("PipelineConfig struct", func() {
5252
"ImageRepoSecret": "IMAGE_REPO_SECRET",
5353
"ImageRepoDockerSecret": "image-repo-auth",
5454
"imageRepo": map[string]interface{}{
55-
"url": "exmaple.com",
56-
"user": "test_user",
55+
"url": "exmaple.com",
56+
"user": "test_user",
57+
"password": "",
5758
},
5859
"dingTalk": nilDingTalkConfig,
5960
"DingTalkSecretKey": "DINGTALK_SECURITY_VALUE",
@@ -94,8 +95,9 @@ var _ = Describe("PipelineConfig struct", func() {
9495
"StepGlobalVars": "",
9596
"RepoType": "gitlab",
9697
"imageRepo": map[string]interface{}{
97-
"url": "exmaple.com",
98-
"user": "test_user",
98+
"url": "exmaple.com",
99+
"user": "test_user",
100+
"password": "",
99101
},
100102
"dingTalk": emptyDingtalk,
101103
"sonarqube": emptySonar,

internal/pkg/plugin/installer/ci/step/github.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package step
22

33
import (
4-
"os"
5-
64
"github.com/devstream-io/devstream/pkg/util/jenkins"
75
"github.com/devstream-io/devstream/pkg/util/log"
86
"github.com/devstream-io/devstream/pkg/util/scm"
9-
"github.com/devstream-io/devstream/pkg/util/scm/github"
107
)
118

129
const (
@@ -15,6 +12,7 @@ const (
1512

1613
type GithubStepConfig struct {
1714
RepoOwner string `mapstructure:"repoOwner"`
15+
Token string `mapstructure:"token"`
1816
}
1917

2018
func (g *GithubStepConfig) GetJenkinsPlugins() []*jenkins.JenkinsPlugin {
@@ -31,7 +29,7 @@ func (g *GithubStepConfig) ConfigJenkins(jenkinsClient jenkins.JenkinsAPI) (*jen
3129
err := jenkinsClient.CreatePasswordCredential(
3230
githubCredentialName,
3331
g.RepoOwner,
34-
os.Getenv(github.TokenEnvKey),
32+
g.Token,
3533
)
3634
if err != nil {
3735
log.Debugf("jenkins preinstall github credentials failed: %s", err)
@@ -52,5 +50,6 @@ func (g *GithubStepConfig) ConfigSCM(client scm.ClientOperation) error {
5250
func newGithubStep(config *StepGlobalOption) *GithubStepConfig {
5351
return &GithubStepConfig{
5452
RepoOwner: config.RepoInfo.GetRepoOwner(),
53+
Token: config.RepoInfo.Token,
5554
}
5655
}

0 commit comments

Comments
 (0)