Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.atlassian.jira.component.ComponentAccessor
- import com.atlassian.jira.event.type.EventDispatchOption
- import com.atlassian.jira.issue.MutableIssue
- import com.atlassian.jira.user.ApplicationUser
- String issueDescription = event.issue.description
- ApplicationUser actor = ComponentAccessor.userManager.getUserByName("automation-agent")
- if (issueDescription ==~ /(?siu).*(?:\{color:[#a-z0-9]+}|\{color}).*/) {
- def regexEmptySpaces = /(?siu)(?:\{color:[#a-z0-9]+}|\{color}|[ \p{Zs}]+)*/
- def regexEmptyLines = /(?siu)(?:\{color:[#a-z0-9]+}|\{color}|[\s\p{Z}]+)+/
- def regexEmailSignatureLogo = /(?<=[\r\n])/ + regexEmptySpaces + /!(?:/ +
- /image[0-9]+\.[a-z]+(?:\|thumbnail)?/ +
- /|https?:\/\/mail\.stoloto\.ru\/res\/StolotoCJSC\.png/ +
- /)!/ + regexEmptySpaces + /(?:[\r\n]{1,2}|\p{Z}|$)/
- def regexEmailSignatures = [
- stoloto: (/(?siu)(?<=[\r\n])/ + regexEmptyLines +
- /(?:\[\{color:[#a-z0-9]+\})?(?:–{3,}|-{3,}|_{3,}|\>{2,})[\s\p{Z}]*С уважением/ +
- /.*?\[/ + regexEmptySpaces + /www\.stoloto\.ru/ + regexEmptySpaces +
- /\|https?:\/\/www\.stoloto\.ru\/?\]/ + regexEmptyLines +
- /(?:/ + regexEmailSignatureLogo + /)?(?=[\r\n])/),
- ]
- for (regexp in regexEmailSignatures) {
- issueDescription = issueDescription.replaceAll(regexp.value, "")
- }
- def regexMessageHistoryQuote = /(?siu)(?:/ +
- /\{quote}.*\{quote}/ +
- /|[\r\n]+\|\{color:[#a-z0-9]+}.*jira-generated-image-avatar.*Atlassian logo\{color:[#a-z0-9]+}.*\{color}\|/ + regexEmptyLines +
- /|\{color:[#a-z0-9]+}—-—-—-—\{color}.*\|https:\/\/jira\.stoloto\.ru\/servicedesk\/customer\/portals]/ + regexEmptyLines +
- /|\{color:[#a-z0-9]+}—-—-—-—\{color}.*(?:jira-generated-image-static-information-|jira-generated-image-avatar-).*/ +
- /)/
- issueDescription = issueDescription.replaceAll(regexMessageHistoryQuote, '')
- def regexEmailHeader = /(?siu)(?<=[\r\n])/ + regexEmptyLines +
- /[\s*]+?(?:from|от|отправитель)(?:\([a-zа-я]\))?:\*?([^\r\n]*)[\r\n]+/ +
- /(?:[\s*]+?(?:sent|отправлено|to|кому|получатель|cc|копия|bcc|скрытая(?: копия)?)(?:\([a-zа-я]\))?:\*?[^\r\n]*[\r\n]+)+/ +
- /[\s*]+?(?:subject|тема)(?:\([a-zа-я]\))?:\*?[^\r\n]*/ +
- regexEmptyLines + /(?=[\r\n]|$)/
- issueDescription = issueDescription.replaceAll(regexEmailHeader + /(?=$)/, "")
- issueDescription = issueDescription.replaceAll(
- regexEmailHeader + /(?:/ + regexEmptyLines + /|/ + regexEmailSignatureLogo + /)+(?=[\r\n]{1,2}|$)/, ""
- )
- issueDescription = issueDescription.replaceAll(regexEmailHeader, "<hr />{color:skyblue}\$1{color}\n")
- issueDescription = issueDescription.replaceAll(/^/ + regexEmptyLines, '')
- issueDescription = issueDescription.replaceAll(/(?siu)(?:\{color:[#a-z0-9]+}|\{color}|----|[\s\p{Z}]+)+$/, '')
- } else if (issueDescription ==~ /(?siu).*(?:<p><font color="[#a-z0-9]+">.*?<\/font><\/p>).*/) {
- def regexEmptySpaces = /(?siu)(?:/ +
- /<p><font color="[#a-z0-9]+"><\/font><\/p>/ +
- /|<p><font color="[#a-z0-9]+"> <\/font><\/p>/ +
- /|<p><\/p>/ +
- /|<p> <\/p>/ +
- /)*/
- def regexEmptyLines = /(?siu)(?:/ +
- /<p><font color="[#a-z0-9]+"><\/font><\/p>/ +
- /|<p><font color="[#a-z0-9]+"> <\/font><\/p>/ +
- /|<p><\/p>/ +
- /|<p> <\/p>/ +
- /|(?<=[\r\n])(?:/ + regexEmptySpaces + /|[ \p{Zs}])*<br(?: \/)?>(?:/ + regexEmptySpaces + /|[ \p{Zs}])*(?=[\r\n])/ +
- /)*/
- def regexEmailSignatures = [
- stoloto: (/(?siu)\<p\>\<font\ color\=\"[#a-z0-9]+\"\>(?:–{3,}|-{3,}|_{3,}|\>{2,})\<br(?:\ \/)?\>/ +
- /[\ \r\n]*С уважением,\<br(?:\ \/)?\>/ +
- /.*?\<\/p\>/),
- ]
- for (regexp in regexEmailSignatures) {
- issueDescription = issueDescription.replaceAll(regexp.value, "")
- }
- def regexEmailHeader = /(?siu)<p>(?:<br(?: \/)?>)?/ +
- /[ \r\n]*(?:<b>)?(?:from|от|отправитель)(?:\([a-zа-я]\))?:(?:<b>)?([^\r\n]*?)<br(?: \/)?>/ +
- /(?:[ \r\n]*(?:<b>)?(?:sent|отправлено|to|кому|получатель|cc|копия|bcc|скрытая(?: копия)?)(?:\([a-zа-я]\))?:(?:<b>)?[^\r\n]*?<br(?: \/)?>)+/ +
- /[ \r\n]*(?:<b>)?(?:subject|тема)(?:\([a-zа-я]\))?:(?:<b>)?[^\r\n]*?/ +
- /<\/p>/
- issueDescription = issueDescription.replaceAll(regexEmptyLines, "")
- issueDescription = issueDescription.replaceAll(regexEmailHeader + /(?=$)/, "")
- issueDescription = issueDescription.replaceAll(regexEmailHeader, "<br><hr /><p style=\"color: skyBlue;\">\$1</p>")
- } else {
- log.warn('@TODO: Simple Text - develop handler')
- }
- MutableIssue mutableIssue = event.issue as MutableIssue
- mutableIssue.description = issueDescription
- ComponentAccessor.issueManager.updateIssue(actor, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement