rule
Notify user if comment contains @username
 
when
comments
.
added
.
isNotEmpty
{
var
separators
=
"
`!#%^&*()=[]{}:;'\"\\|,<>/?\n\r\t
"
;
var
mentionedUsers
=
"
 
"
;
 
var
myComment
=
comments
.
added
.
first
;
var
originalText
=
myComment
.
text
;
var
text
=
"
 
"
+
originalText
.
lowerCase
+
"
 
"
;
 
var
username
=
"
 
"
;
var
user
=
loggedInUser
;
var
index
=
-1
;
 
index
=
text
.
indexOf
(
"
@
"
,
opts
)
;
 
while
(
index
!=
-1
)
{
index
=
index
+
1
;
username
=
"
 
"
;
 
var
nextSymbol
=
text
.
substring
(
index
,
index
+
1
)
;
while
(
!
separators
.
contains
(
nextSymbol
,
opts
)
)
{
username
=
username
+
nextSymbol
;
index
=
index
+
1
;
nextSymbol
=
text
.
substring
(
index
,
index
+
1
)
;
}
 
if
(
username
.
endsWith
(
"
.
"
,
opts
)
)
{
username
=
username
.
substringOfLength
(
username
.
length
-
1
,
opts
)
;
}
 
debug
(
"
Extracted @username: |
"
+
username
+
"
|
"
)
;
if
(
username
.
isNotEmpty
)
{
user
=
project
.
getUser
(
username
)
;
 
if
(
user
!=
null
&&
!
mentionedUsers
.
contains
(
"
@
"
+
user
.
login
+
"
,
"
,
ignoreCase
)
&&
(
user
.
isInGroup
(
permittedGroup
.
name
)
||
permittedGroup
==
null
||
user
==
reporter
)
&&
(
myComment
.
permittedGroup
==
null
||
user
.
isInGroup
(
myComment
.
permittedGroup
.
name
)
)
)
{
user
.
notify
(
l10n
(
{
getId
(
 
)
}
{
summary
}
)
,
l10n
(
<p style="font-size:14px; font-family: sans-serif; color:#000000; margin:14px 0 19px 44px">You were mentioned in the comment by <b>
{
myComment
.
author
.
fullName
}
</b> in project
{
project
.
name
}
at
{
myComment
.
created
.
format
(
mediumDateTime
)
}
</p><table style="border-collapse: collapse; width: 100%; table-layout: fixed;"> <tbody> <tr> <td style="padding:12px 15px; background:#f0f0f0"> <table style="border-collapse: collapse; border: 0; width: 100%;"> <tbody> <tr> <td style="vertical-align: top; font-family:sans-serif; font-size: 13px;"><a title="YouTrack" style="float:left; margin-right:6px; font-size: 15px; color: #1466c6; text-decoration: none;" href="
{
getUrl
(
 
)
}
">
{
getId
(
 
)
}
"</a> <a style="font-size: 15px; color: #1466c6; text-decoration: none;" href="
{
getUrl
(
 
)
}
">
{
summary
}
</a> </td> </tr> </tbody> </table> </td> </tr> </tbody></table></p>
<table style="width: 100%; border-collapse: collapse; border: 0;"><tr><td style="padding: 10px 0 10px 10px; vertical-align: top; font-family:sans-serif; font-size:13px; background:#f0f0f0; border-top: 8px solid #ffffff;">
{
wikify
(
originalText
)
}
</td></tr></table>
<p style="color: gray;font-size: 12px;margin-top: 1em;border-top: 1px solid #D4D5D6">You (<b>
{
user
.
login
}
</b>) received this message because you've been mentioned in the comment.
Sincerely yours, YouTrack</p>
)
,
true
)
;
mentionedUsers
=
mentionedUsers
+
"
@
"
+
user
.
login
+
"
,
"
;
}
}
 
text
=
text
.
substringRelative
(
"
@
"
+
username
,
pos
:
after
)
;
index
=
text
.
indexOf
(
"
@
"
,
opts
)
;
}
}