Searching for or splitting by line break

Hi

I'm using the code from the repository to recognize a user from the comments.
In your repository there is a check to find usernames by searching text between @ and a space. I modified this to also search for "," and ":" but I can't handle the situation when they put an enter behind the user name.
For this I think I have 2 posibilities:
1. split the text into multiple lines and append a space to each line before searching
2. be able to search for a substring between "@" and something like "CR/LF".

Current code:
rule Recognize user from comment

when comments.added.isNotEmpty {
  var mcomments = comments.added.first.text + " ";
  var extractedUsername = mcomments.substringBetween("@", " ");
  if (extractedUsername == null) {
    extractedUsername = mcomments.substringBetween("@", ":");
  }
  if (extractedUsername == null) {
    extractedUsername = mcomments.substringBetween("@", ",");
  }
   
  if (extractedUsername != null && extractedUsername.isNotBlank) {
    var extractedUser = project.getUser(extractedUsername);
    if (extractedUser != null && !extractedUser.getIssues(Everything, "tag: Star").contains(issue)) {
      extractedUser.watchIssue(issue);
      extractedUser.notify(issue.getId() + ": " + issue.description, "You (" + (extractedUser.fullName) + ") were mentioned in comment of issue " + "<a href=\"" + getUrl() + "\">" + getId() + "</a>:" + "<br><div style=\"color: #666666;margin-top: .7em;font-size: 90%;font-style: italic\">" + ">" + comments.added.first.text + "</div>", true);
    }
  }
}
2 comments
Comment actions Permalink
You can use "\n" to match new line or just wait full featured default workflow JT-3869.
0

Please sign in to leave a comment.