Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enrich with regex can not match #8090

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions backend/helpers/pluginhelper/api/enrich_with_regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions backend/plugins/github_graphql/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func ConvertDeployment(taskCtx plugin.SubTaskContext) errors.Error {
deploymentCommit.Environment = devops.PRODUCTION
}
}

deploymentCommit.CicdDeploymentId = deploymentCommit.Id
return []interface{}{
deploymentCommit,
Expand Down
Loading