...
Info |
---|
|
API | Notes |
---|---|
| Get all headers of a message. |
| Get value of a message header Parameters
|
| Set the value of a message header Parameters
|
| Adds output that is recorded during execution and shown in the processing report. Parameters
|
| Set the processing outcome of the script Parameters
|
| See below. https://nodejs.org/api/assert.html |
| Regular expressions can be evaluated within the script. This is often used for searches within string values for matching content. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp for more information. |
Assertions
See https://nodejs.org/api/assert.html for full Assert API documentation.
...
Code Block |
---|
assert.equal(message.getHeader("example"), '10', 'example header value not found'); |
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'); |