JD2022-TU1/data/EngineData/SubmitAssistant/util/regex.js

87 lines
4.1 KiB
JavaScript

/**
* Regular expressions file.
*/
define([
"constants",
],
function(constants){
//tags accept only alphanumeric, '_' and ',' characters
var first_tag = new RegExp("^\\[([\\w,]+)\\]\\[[\\w,]+\\][^]+$");
var second_tag = new RegExp("^\\[[\\w,]+\\]\\[([\\w,]+)\\][^]+$");
/**
* JIRA, if exists, is always in third position.
* JIRA keys: an alphanumeric prefix, a '-' and a numeric suffix (bug number).
* Repeat pattern 0..n times with a comma as separator at the beginning.
*/
var jira_tag = new RegExp("^\\[[\\w,]+\\]\\[[\\w,]+\\]\\[(\\w+-\\d+(,\\w+-\\d+)*)\\][^]*");
/**
* Preflight tag regular expression
*/
var preflight_tag = new RegExp("\\[(Preflight-\\d+,[A-Z_]+)\\]");
/**
* 1st case: description is between the jira tag and the changelog tag (optional "*")
* 2nd case: description is between the type tag and the changelog tag (no jira tag, optional "*")
* 3rd case: description is between the jira tag and the reviewer (no changelog, required "+")
* 4th case: description is between the type tag and the reviewer (no jira tag, no changelog, required "+")
* 5rd case: description is between the jira tag and the validator (no changelog, required "+")
* 6th case: description is between the type tag and the reviewer (no jira tag, no changelog, required "+")
* 7th case: description is at the end, after jira tag (no changelog, no reviewer, required "+")
* 8th case: description is at the end (no jira tag, no changelog, no reviewer, required "+")
*/
var desc_code = new RegExp("^\\[[\\w,]+\\]\\[\\w+\\]\\[\\w+-\\d+(,\\w+-\\d+)*\\]([^]*)\\[" + constants.changelog + "\\]|"
+ "^\\[[\\w,]+\\]\\[\\w+\\]([^]*)\\[" + constants.changelog + "\\]|"
+ "^\\[[\\w,]+\\]\\[\\w+\\]\\[\\w+-\\d+(,\\w+-\\d+)*\\]([^]+)" + constants.reviewer + "|"
+ "^\\[[\\w,]+\\]\\[\\w+\\]([^]+)" + constants.reviewer + "|"
+ "^\\[[\\w,]+\\]\\[\\w+\\]\\[\\w+-\\d+(,\\w+-\\d+)*\\]([^]+)" + constants.validator + "|"
+ "^\\[[\\w,]+\\]\\[\\w+\\]([^]+)" + constants.validator + "|"
+ "^\\[[\\w,]+\\]\\[\\w+\\]\\[\\w+-\\d+(,\\w+-\\d+)*\\]([^]+)$|"
+ "^\\[[\\w,]+\\]\\[\\w+\\]([^]+)$");
/**
* 1st case: description is between jira tag and validator
* 2nd case: description is between map tag and validator (no jira tag)
* 3rd case: description is after jira tag
* 4th case: description is after map tag (no jira tag)
*/
var desc_data = new RegExp("^\\[[\\w,]+\\]\\[[\\w,]+\\]\\[\\w+-\\d+(,\\w+-\\d+)*\\]([^]+)" + constants.validator + "|"
+ "^\\[[\\w,]+\\]\\[[\\w,]+\\]([^]+)" + constants.validator + "|"
+ "^\\[[\\w,]+\\]\\[[\\w,]+\\]\\[\\w+-\\d+(,\\w+-\\d+)*\\]([^]+)$|"
+ "^\\[[\\w,]+\\]\\[[\\w,]+\\]([^]+)$");
/**
* 1st case: changelog is between the changelog tag and the reviewer
* 2nd case: changelog is between the changelog tag and the validator (no reviewer)
* 3rd case: changelog is at the end (no reviewer)
*/
var changelog = new RegExp("\\[" + constants.changelog + "\\]([^]+)" + constants.reviewer + "|"
+ "\\[" + constants.changelog + "\\]([^]+)" + constants.validator + "|"
+ "\\[" + constants.changelog + "\\]([^]+)$");
//use unicode to include accent and other french characters
var reviewer = new RegExp(constants.reviewer + "([A-Za-z\u00C0-\u017F '-]+.*)\n$");
var changelog_tag = new RegExp("\\[" + constants.changelog + "\\]", "i");
var reviewer_tag = new RegExp(constants.reviewer, "i");
var validator_tag = new RegExp(constants.validator, "i");
return {
first_tag: first_tag,
second_tag: second_tag,
jira_tag: jira_tag,
preflight_tag: preflight_tag,
desc_code: desc_code,
desc_data: desc_data,
changelog: changelog,
reviewer: reviewer,
changelog_tag: changelog_tag,
reviewer_tag: reviewer_tag,
validator_tag: validator_tag,
};
}
);