This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch zk-0918-3
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/zk-0918-3 by this push:
new 693bd9794 fix: update gitlab trans-to-deployment scope config to
pointer
693bd9794 is described below
commit 693bd9794e3190f84e257cd378988e21e1617101
Author: abeizn <[email protected]>
AuthorDate: Wed Sep 18 12:18:33 2024 +0800
fix: update gitlab trans-to-deployment scope config to pointer
---
backend/plugins/gitlab/impl/impl.go | 12 ++++++++----
backend/plugins/gitlab/models/scope_config.go | 4 ++--
backend/plugins/gitlab/tasks/job_convertor.go | 7 ++++---
backend/plugins/gitlab/tasks/pipeline_detail_extractor.go | 6 ++++--
4 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/backend/plugins/gitlab/impl/impl.go
b/backend/plugins/gitlab/impl/impl.go
index 8bf6f9235..d292db691 100644
--- a/backend/plugins/gitlab/impl/impl.go
+++ b/backend/plugins/gitlab/impl/impl.go
@@ -206,11 +206,15 @@ func (p Gitlab) PrepareTaskData(taskCtx
plugin.TaskContext, options map[string]i
}
regexEnricher := helper.NewRegexEnricher()
- if err := regexEnricher.TryAdd(devops.DEPLOYMENT,
op.ScopeConfig.DeploymentPattern); err != nil {
- return nil, errors.BadInput.Wrap(err, "invalid value for
`deploymentPattern`")
+ if op.ScopeConfig.DeploymentPattern != nil {
+ if err := regexEnricher.TryAdd(devops.DEPLOYMENT,
*op.ScopeConfig.DeploymentPattern); err != nil {
+ return nil, errors.BadInput.Wrap(err, "invalid value
for `deploymentPattern`")
+ }
}
- if err := regexEnricher.TryAdd(devops.PRODUCTION,
op.ScopeConfig.ProductionPattern); err != nil {
- return nil, errors.BadInput.Wrap(err, "invalid value for
`productionPattern`")
+ if op.ScopeConfig.ProductionPattern != nil {
+ if err := regexEnricher.TryAdd(devops.PRODUCTION,
*op.ScopeConfig.ProductionPattern); err != nil {
+ return nil, errors.BadInput.Wrap(err, "invalid value
for `productionPattern`")
+ }
}
if len(op.ScopeConfig.EnvNameList) > 0 ||
(len(op.ScopeConfig.EnvNameList) == 0 && op.ScopeConfig.EnvNamePattern == "") {
if err = regexEnricher.TryAddList(devops.ENV_NAME_PATTERN,
op.ScopeConfig.EnvNameList...); err != nil {
diff --git a/backend/plugins/gitlab/models/scope_config.go
b/backend/plugins/gitlab/models/scope_config.go
index 63f6ab7d8..35cb4ae9d 100644
--- a/backend/plugins/gitlab/models/scope_config.go
+++ b/backend/plugins/gitlab/models/scope_config.go
@@ -33,8 +33,8 @@ type GitlabScopeConfig struct {
IssueTypeBug string `mapstructure:"issueTypeBug"
json:"issueTypeBug"`
IssueTypeIncident string
`mapstructure:"issueTypeIncident" json:"issueTypeIncident"`
IssueTypeRequirement string
`mapstructure:"issueTypeRequirement" json:"issueTypeRequirement"`
- DeploymentPattern string
`mapstructure:"deploymentPattern" json:"deploymentPattern"`
- ProductionPattern string
`mapstructure:"productionPattern,omitempty" json:"productionPattern"
gorm:"type:varchar(255)"`
+ DeploymentPattern *string
`mapstructure:"deploymentPattern" json:"deploymentPattern"`
+ ProductionPattern *string
`mapstructure:"productionPattern,omitempty" json:"productionPattern"
gorm:"type:varchar(255)"`
EnvNamePattern string
`mapstructure:"envNamePattern,omitempty" json:"envNamePattern"
gorm:"type:varchar(255)"`
EnvNameList []string
`gorm:"type:json;serializer:json" json:"envNameList" mapstructure:"envNameList"`
Refdiff datatypes.JSONMap
`mapstructure:"refdiff,omitempty" json:"refdiff" swaggertype:"object"
format:"json"`
diff --git a/backend/plugins/gitlab/tasks/job_convertor.go
b/backend/plugins/gitlab/tasks/job_convertor.go
index 58bd8f712..e6e14a41f 100644
--- a/backend/plugins/gitlab/tasks/job_convertor.go
+++ b/backend/plugins/gitlab/tasks/job_convertor.go
@@ -103,9 +103,10 @@ func ConvertJobs(taskCtx plugin.SubTaskContext) (err
errors.Error) {
},
CicdScopeId:
projectIdGen.Generate(data.Options.ConnectionId, gitlabJob.ProjectId),
}
- domainJob.Type =
regexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, gitlabJob.Name)
- domainJob.Environment =
regexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, gitlabJob.Name)
-
+ if data.Options.ScopeConfig.DeploymentPattern != nil ||
data.Options.ScopeConfig.ProductionPattern != nil {
+ domainJob.Type =
regexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, gitlabJob.Name)
+ domainJob.Environment =
regexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, gitlabJob.Name)
+ }
return []interface{}{
domainJob,
}, nil
diff --git a/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
b/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
index 94d45a4f2..34692dc54 100644
--- a/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
+++ b/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
@@ -67,10 +67,12 @@ func ExtractApiPipelineDetails(taskCtx
plugin.SubTaskContext) errors.Error {
Duration: gitlabApiPipeline.Duration,
QueuedDuration:
gitlabApiPipeline.QueuedDuration,
ConnectionId: data.Options.ConnectionId,
- Type:
data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT,
gitlabApiPipeline.Ref),
- Environment:
data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION,
gitlabApiPipeline.Ref),
Source: gitlabApiPipeline.Source,
}
+ if data.Options.ScopeConfig.DeploymentPattern != nil ||
data.Options.ScopeConfig.ProductionPattern != nil {
+ gitlabPipeline.Type =
data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, gitlabApiPipeline.Ref)
+ gitlabPipeline.Environment =
data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION,
gitlabApiPipeline.Ref)
+ }
return []interface{}{gitlabPipeline}, nil
},