Skip to content

Commit

Permalink
fix: enrich with regex can not match (#8090)
Browse files Browse the repository at this point in the history
* fix: enrich with regex can not match
  • Loading branch information
abeizn authored Sep 23, 2024
1 parent e4c6554 commit 7d8adad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
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

0 comments on commit 7d8adad

Please sign in to comment.