Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Using Regex to match a Lower Case Issue Key and remove the Issue Key from the Subject

Currently, the Regexp that is used by JEMHC to search for matching Issue Key’s is case insensitive which means that even if a Lowercase version of the issuekey is within the subject then it will be used for commenting. The below script will check for a lowercase Issue Key and if one is found then it will remove the matching Issue Key from the email subject, which then allows the issue to be created instead of commenting.

Example Script:

Code Block
var pattern = new RegExp("([a-z0-9]+-[0-9]+)").exec(message.getSubject());
if (pattern !== null)
{
    print("matched value is: " + pattern[1]);
    message.setHeader("Subject", message.getSubject().replace(pattern[1],""));
}

Example Test Case:

“cm-4” is the example Issuekey

Code Block
MIME-Version: 1.0
Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT)
Date: Sun, 19 Jun 2011 17:42:26 +1200
Subject: CHANGE_SUBJECT!!! cm-4
From: ryan@thepluginpeople.com
To: test@test.com
Content-Type: text/plain; charset=UTF-8
CHANGE BODY!!!

Example Test Script:

Code Block
assert.equal(message.getSubject(), 'CHANGE_SUBJECT!!! ', 'example header value not found');