Skip to content

Commit

Permalink
[Issue #5] Support disallow prefixes (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakputhraya authored Oct 3, 2020
1 parent 68ab463 commit 2371b3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
17 changes: 13 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,15 +44,23 @@ 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))) {
core.setFailed(`Pull Request title "${title}" did not match any of the prefixes - ${prefixes}`);
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);
}
Expand Down

0 comments on commit 2371b3f

Please sign in to comment.