This is an automated email from the ASF dual-hosted git repository. mintsweet pushed a commit to branch feat-dora-config in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit ae51c3d5bf6c6fb2ed8799605d5070c04c37bae6 Author: abeizn <zikuan...@merico.dev> AuthorDate: Mon Sep 23 12:07:49 2024 +0800 fix: enrich with regex can not match (#8090) * fix: enrich with regex can not match --- backend/helpers/pluginhelper/api/enrich_with_regex.go | 10 ++-------- backend/plugins/github_graphql/impl/impl.go | 10 ++++++++-- backend/plugins/github_graphql/tasks/deployment_convertor.go | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/backend/helpers/pluginhelper/api/enrich_with_regex.go b/backend/helpers/pluginhelper/api/enrich_with_regex.go index d586b8187..4425fe321 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 == "" { @@ -138,19 +137,14 @@ func (r *RegexEnricher) ReturnNameIfMatchedList(name string, targets ...string) return "" } else { 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 "" - } } + return "" // If any regex fails to match, return "" } - return name // Return name if all regex conditions were fulfilled } // ReturnNameIfOmittedOrMatched returns the given name if regex of the given name is omitted or fallback to ReturnNameIfMatched 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,