klesh commented on code in PR #4886:
URL: 
https://github.com/apache/incubator-devlake/pull/4886#discussion_r1162576015


##########
backend/helpers/pluginhelper/api/enrich_with_regex.go:
##########
@@ -64,3 +67,33 @@ func (r *RegexEnricher) GetEnrichResult(pattern string, v 
string, result string)
        }
        return ""
 }
+
+// TryAdd a named regexp if given pattern is not empty
+func (r *RegexEnricher) TryAdd(name, pattern string) errors.Error {
+       if pattern == "" {
+               return nil
+       }
+       if _, ok := r.regexpMap[name]; ok {
+               return errors.Default.New(fmt.Sprintf("Regex pattern with name: 
%s already exists", name))
+       }
+       regex, err := errors.Convert01(regexp.Compile(pattern))
+       if err != nil {
+               return errors.BadInput.Wrap(err, fmt.Sprintf("Fail to compile 
pattern for regex pattern: %s", pattern))
+       }
+       r.regexpMap[name] = regex
+       return nil
+}
+
+// ReturnNameIfMatched will return name if any of the targets matches the 
regex with the given name
+func (r *RegexEnricher) ReturnNameIfMatched(name string, targets ...string) 
string {

Review Comment:
   Alright, will do



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to