IncomingEmail mail = getIncomingEmail();
string issueKey = matchText(mail.subject, "[A-Z][A-Z]+-[0-9]+"); // find an issue key in the subject
if(isNull(issueKey)) {
// if no issue key found, create a new issue;
if(issueExists(issueKey)) {
// add comment
string commentText = mail.body;
string userCommenting = getUserByEmail(mail.from).key;
addComment(issueKey, userCommenting, commentText);
attachAllFilesFromEmail(issueKey);
} else {
// create issue
string summary = mail.subject;
string []description fields = {}mail.body;
string [] fields += {"reporter", currentUserKey()};
fields += {"assigneereporter", getUserByEmail(mail.cc[0]from).key};
string newIssue = createIssue("TESTSCRUM", "", "Task", summary mail.subject, "Minor", mail.bodydescription, {}, "", "", 0, fields);
attachAllFilesFromEmail(newIssue);
%newIssue%.watchers = getUserKeysFromEmails(mail.cc);
} else {
// if issue key found in subject, add a comment
addComment(issueKey, currentUserKey(), mail.body);
} |