diff options
author | Florian Zschocke <florian.zschocke@devolo.de> | 2016-12-12 22:59:12 +0100 |
---|---|---|
committer | Florian Zschocke <florian.zschocke@devolo.de> | 2016-12-12 22:59:12 +0100 |
commit | 9a51d2bf8ed3663715fc735afb0444e179c334f7 (patch) | |
tree | a266d07fe861e255d9dd8dd431b7edb37cb3e3e8 /src/main | |
parent | 6b0ac4155c4643de10a14166318f73e23616d36f (diff) | |
parent | 7985115bd1301db867935b52a689ccfc32f13794 (diff) | |
download | gitblit-9a51d2bf8ed3663715fc735afb0444e179c334f7.tar.gz gitblit-9a51d2bf8ed3663715fc735afb0444e179c334f7.zip |
Merge branch 'fixMentionsInTickets-985'
Diffstat (limited to 'src/main')
4 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/com/gitblit/Constants.java b/src/main/java/com/gitblit/Constants.java index 321f84f9..ab503bd3 100644 --- a/src/main/java/com/gitblit/Constants.java +++ b/src/main/java/com/gitblit/Constants.java @@ -62,6 +62,12 @@ public class Constants { public static final String GIT_PATH = "/git/";
public static final String REGEX_SHA256 = "[a-fA-F0-9]{64}";
+
+ /**
+ * This regular expression is used when searching for "mentions" in tickets
+ * (when someone writes @thisOtherUser)
+ */
+ public static final String REGEX_TICKET_MENTION = "\\B@(?<user>[^\\s]+)\\b";
public static final String ZIP_PATH = "/zip/";
diff --git a/src/main/java/com/gitblit/models/TicketModel.java b/src/main/java/com/gitblit/models/TicketModel.java index d5345891..65e29dc0 100644 --- a/src/main/java/com/gitblit/models/TicketModel.java +++ b/src/main/java/com/gitblit/models/TicketModel.java @@ -43,6 +43,8 @@ import java.util.regex.Pattern; import org.eclipse.jgit.util.RelativeDateFormatter; +import com.gitblit.Constants; + /** * The Gitblit Ticket model, its component classes, and enums. * @@ -773,10 +775,10 @@ public class TicketModel implements Serializable, Comparable<TicketModel> { } try { - Pattern mentions = Pattern.compile("\\s@([A-Za-z0-9-_]+)"); + Pattern mentions = Pattern.compile(Constants.REGEX_TICKET_MENTION); Matcher m = mentions.matcher(text); while (m.find()) { - String username = m.group(1); + String username = m.group("user"); plusList(Field.mentions, username); } } catch (Exception e) { diff --git a/src/main/java/com/gitblit/tickets/TicketNotifier.java b/src/main/java/com/gitblit/tickets/TicketNotifier.java index 8c7fe6d4..b913db25 100644 --- a/src/main/java/com/gitblit/tickets/TicketNotifier.java +++ b/src/main/java/com/gitblit/tickets/TicketNotifier.java @@ -573,10 +573,10 @@ public class TicketNotifier { // cc users mentioned in last comment Change lastChange = ticket.changes.get(ticket.changes.size() - 1); if (lastChange.hasComment()) { - Pattern p = Pattern.compile("\\s@([A-Za-z0-9-_]+)"); + Pattern p = Pattern.compile(Constants.REGEX_TICKET_MENTION); Matcher m = p.matcher(lastChange.comment.text); while (m.find()) { - String username = m.group(); + String username = m.group("user"); ccs.add(username); } } diff --git a/src/main/java/com/gitblit/utils/MarkdownUtils.java b/src/main/java/com/gitblit/utils/MarkdownUtils.java index e0c9dd4e..8371b3c6 100644 --- a/src/main/java/com/gitblit/utils/MarkdownUtils.java +++ b/src/main/java/com/gitblit/utils/MarkdownUtils.java @@ -30,6 +30,7 @@ import org.pegdown.ParsingTimeoutException; import org.pegdown.PegDownProcessor;
import org.pegdown.ast.RootNode;
+import com.gitblit.Constants;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.wicket.MarkupProcessor.WorkaroundHtmlSerializer;
@@ -137,8 +138,8 @@ public class MarkdownUtils { String canonicalUrl = settings.getString(Keys.web.canonicalUrl, "https://localhost:8443");
// emphasize and link mentions
- String mentionReplacement = String.format(" **[@$1](%1s/user/$1)**", canonicalUrl);
- text = text.replaceAll("\\s@([A-Za-z0-9-_]+)", mentionReplacement);
+ String mentionReplacement = String.format("**[@${user}](%1s/user/${user})**", canonicalUrl);
+ text = text.replaceAll(Constants.REGEX_TICKET_MENTION, mentionReplacement);
// link ticket refs String ticketReplacement = MessageFormat.format("$1[#$2]({0}/tickets?r={1}&h=$2)$3", canonicalUrl, repositoryName); |