diff --git a/action.yml b/action.yml index 70b4fe9c..30fc4bea 100644 --- a/action.yml +++ b/action.yml @@ -4,19 +4,28 @@ author: 'deepakputhraya' inputs: regex: description: 'Regex to validate the pull request title' + required: false default: '.+' allowed_prefixes: description: 'Comma separated list of prefix allowed to be used in title. eg: feature,hotfix,JIRA-' + required: false + default: '' + disallowed_prefixes: + description: 'Comma separated list of prefix disallowed to be used in title. eg: feat,fix' + required: false default: '' prefix_case_sensitive: - description: 'Are the allowed prefixes case sensitive?' - default: false + description: 'Are the allowed & disallowed prefixes case sensitive?' + required: false + default: 'false' min_length: description: 'Min length of title' - default: 1 + required: false + default: '1' max_length: description: 'Max length of title. -1 to ignore the rule' - default: -1 + required: false + default: '-1' runs: using: 'node12' diff --git a/index.js b/index.js index 5d502849..fd20eb50 100644 --- a/index.js +++ b/index.js @@ -22,9 +22,9 @@ async function run() { const title = github.context.payload.pull_request.title; core.info(`Pull Request title: "${title}"`); + // Check if title pass regex const regex = RegExp(core.getInput('regex')); - core.info(`Regex: ${regex}`); if (!regex.test(title)) { core.setFailed(`Pull Request title "${title}" failed to pass match regex - ${regex}`); return @@ -44,8 +44,8 @@ async function run() { return } - // Check if title starts with a prefix - const prefixes = core.getInput('allowed_prefixes'); + // Check if title starts with an allowed prefix + let prefixes = core.getInput('allowed_prefixes'); const prefixCaseSensitive = (core.getInput('prefix_case_sensitive') === 'true'); core.info(`Allowed Prefixes: ${prefixes}`); if (prefixes.length > 0 && !prefixes.split(',').some((el) => validateTitlePrefix(title, el, prefixCaseSensitive))) { @@ -53,6 +53,14 @@ async function run() { return } + // Check if title starts with a disallowed prefix + prefixes = core.getInput('disallowed_prefixes'); + core.info(`Disallowed Prefixes: ${prefixes}`); + if (prefixes.length > 0 && prefixes.split(',').some((el) => validateTitlePrefix(title, el, prefixCaseSensitive))) { + core.setFailed(`Pull Request title "${title}" matched with a disallowed prefix - ${prefixes}`); + return + } + } catch (error) { core.setFailed(error.message); }