This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch zk-0918-2
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/zk-0918-2 by this push:
new c35383dfe fix: update gitlab trans-to-deployment scope config to
pointer
c35383dfe is described below
commit c35383dfebe8311c87a4c616c9af6a94555e99c1
Author: abeizn <[email protected]>
AuthorDate: Wed Sep 18 11:58:14 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 | 6 ++++--
backend/plugins/gitlab/tasks/pipeline_detail_extractor.go | 6 ++++--
4 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/backend/plugins/gitlab/impl/impl.go
b/backend/plugins/gitlab/impl/impl.go
index 2d4dbb4fc..04dc8fabe 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 err := regexEnricher.TryAdd(devops.ENV_NAME_PATTERN,
op.ScopeConfig.EnvNamePattern); err != nil {
return nil, errors.BadInput.Wrap(err, "invalid value for
`envNamePattern`")
diff --git a/backend/plugins/gitlab/models/scope_config.go
b/backend/plugins/gitlab/models/scope_config.go
index 78cfd7f2d..7de1304a6 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)"`
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..99b8ef64c 100644
--- a/backend/plugins/gitlab/tasks/job_convertor.go
+++ b/backend/plugins/gitlab/tasks/job_convertor.go
@@ -103,8 +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,
diff --git a/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
b/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
index 1b78362a1..c1c5708e8 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.ReturnNameIfMatched(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.ReturnNameIfMatched(devops.PRODUCTION, gitlabApiPipeline.Ref)
+ }
return []interface{}{gitlabPipeline}, nil
},