This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch zk-0923
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/zk-0923 by this push:
new c91748fd6 fix: enrich with regex can not match
c91748fd6 is described below
commit c91748fd653831e453efb7478d5e205332723522
Author: abeizn <[email protected]>
AuthorDate: Mon Sep 23 11:24:27 2024 +0800
fix: enrich with regex can not match
---
backend/helpers/pluginhelper/api/enrich_with_regex.go | 11 +++++------
backend/plugins/github_graphql/impl/impl.go | 10 ++++++++--
backend/plugins/github_graphql/tasks/deployment_convertor.go | 1 -
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/enrich_with_regex.go
b/backend/helpers/pluginhelper/api/enrich_with_regex.go
index d586b8187..cbae9fd62 100644
--- a/backend/helpers/pluginhelper/api/enrich_with_regex.go
+++ b/backend/helpers/pluginhelper/api/enrich_with_regex.go
@@ -112,7 +112,6 @@ func (r *RegexEnricher) TryAddList(name string, patterns
...string) errors.Error
if _, ok := r.regexMapList[name]; ok {
return errors.Default.New(fmt.Sprintf("Regex pattern with name:
%s already exists", name))
}
-
var regexList []*regexp.Regexp
for _, pattern := range patterns {
if pattern == "" {
@@ -137,17 +136,17 @@ func (r *RegexEnricher) ReturnNameIfMatchedList(name
string, targets ...string)
if regexList, ok := r.regexMapList[name]; !ok {
return ""
} else {
+ matched := false
for _, regex := range regexList {
- matched := false
for _, target := range targets {
if regex.MatchString(target) {
matched = true
- break
+ return name
}
}
- if !matched {
- return "" // If any regex fails to match,
return ""
- }
+ }
+ if !matched {
+ return "" // If any regex fails to match, return ""
}
}
return name // Return name if all regex conditions were fulfilled
diff --git a/backend/plugins/github_graphql/impl/impl.go
b/backend/plugins/github_graphql/impl/impl.go
index 5b82c753c..3de0cf345 100644
--- a/backend/plugins/github_graphql/impl/impl.go
+++ b/backend/plugins/github_graphql/impl/impl.go
@@ -263,8 +263,14 @@ func (p GithubGraphql) PrepareTaskData(taskCtx
plugin.TaskContext, options map[s
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`")
+ 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 {
+ return nil, errors.BadInput.Wrap(err, "invalid value
for `envNameList`")
+ }
+ } else {
+ if err = regexEnricher.TryAdd(devops.ENV_NAME_PATTERN,
op.ScopeConfig.EnvNamePattern); err != nil {
+ return nil, errors.BadInput.Wrap(err, "invalid value
for `envNamePattern`")
+ }
}
taskData.RegexEnricher = regexEnricher
diff --git a/backend/plugins/github_graphql/tasks/deployment_convertor.go
b/backend/plugins/github_graphql/tasks/deployment_convertor.go
index c0b6a29aa..6d292de56 100644
--- a/backend/plugins/github_graphql/tasks/deployment_convertor.go
+++ b/backend/plugins/github_graphql/tasks/deployment_convertor.go
@@ -108,7 +108,6 @@ func ConvertDeployment(taskCtx plugin.SubTaskContext)
errors.Error {
deploymentCommit.Environment =
devops.PRODUCTION
}
}
-
deploymentCommit.CicdDeploymentId = deploymentCommit.Id
return []interface{}{
deploymentCommit,