diff --git a/README.md b/README.md index 605f93b10..320df8739 100644 --- a/README.md +++ b/README.md @@ -65,13 +65,6 @@ The action works without configuration, however you can provide options for cust The subject "{subject}" found in the pull request title "{title}" didn't match the configured pattern. Please ensure that the subject doesn't start with an uppercase character. - # For work-in-progress PRs you can typically use draft pull requests - # from GitHub. However, private repositories on the free plan don't have - # this option and therefore this action allows you to opt-in to using the - # special "[WIP]" prefix to indicate this state. This will avoid the - # validation of the PR title and the pull request checks remain pending. - # Note that a second check will be reported if this is enabled. - wip: true # When using "Squash and merge" on a PR with only one commit, GitHub # will suggest using that commit message instead of the PR title for the # merge commit, and it's easy to commit this by mistake. Enable this option @@ -89,6 +82,20 @@ The action works without configuration, however you can provide options for cust ignoreLabels: | bot ignore-semantic-pull-request + # If you're using a format for the PR title that differs from the traditional Conventional + # Commits spec, you can use these options to customize the parsing of the type, scope and + # subject. The `headerPattern` should contain a regex where the capturing groups in parentheses + # correspond to the parts listed in `headerPatternCorrespondence`. + # See: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#headerpattern + headerPattern: '^(\w*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$' + headerPatternCorrespondence: type, scope, subject + # For work-in-progress PRs you can typically use draft pull requests + # from GitHub. However, private repositories on the free plan don't have + # this option and therefore this action allows you to opt-in to using the + # special "[WIP]" prefix to indicate this state. This will avoid the + # validation of the PR title and the pull request checks remain pending. + # Note that a second check will be reported if this is enabled. + wip: true ``` ## Event triggers diff --git a/action.yml b/action.yml index c4699ab92..8f9d8a130 100644 --- a/action.yml +++ b/action.yml @@ -23,9 +23,6 @@ inputs: subjectPatternError: description: "If `subjectPattern` is configured, you can use this property to override the default error message that is shown when the pattern doesn't match. The variables `subject` and `title` can be used within the message." required: false - wip: - description: "For work-in-progress PRs you can typically use draft pull requests from Github. However, private repositories on the free plan don't have this option and therefore this action allows you to opt-in to using the special '[WIP]' prefix to indicate this state. This will avoid the validation of the PR title and the pull request checks remain pending. Note that a second check will be reported if this is enabled." - required: false validateSingleCommit: description: "When using \"Squash and merge\" on a PR with only one commit, GitHub will suggest using that commit message instead of the PR title for the merge commit, and it's easy to commit this by mistake. Enable this option to also validate the commit message for one commit PRs." required: false @@ -38,3 +35,12 @@ inputs: ignoreLabels: description: "If the PR contains one of these labels, the validation is skipped. Multiple labels can be separated by newlines. If you want to rerun the validation when labels change, you might want to use the `labeled` and `unlabeled` event triggers in your workflow." required: false + headerPattern: + description: "If you're using a format for the PR title that differs from the traditional Conventional Commits spec, you can use this to customize the parsing of the type, scope and subject. The `headerPattern` should contain a regex where the capturing groups in parentheses correspond to the parts listed in `headerPatternCorrespondence`. For more details see: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#headerpattern" + required: false + headerPatternCorrespondence: + description: "If `headerPattern` is configured, you can use this to define which capturing groups correspond to the type, scope and subject." + required: false + wip: + description: "For work-in-progress PRs you can typically use draft pull requests from Github. However, private repositories on the free plan don't have this option and therefore this action allows you to opt-in to using the special '[WIP]' prefix to indicate this state. This will avoid the validation of the PR title and the pull request checks remain pending. Note that a second check will be reported if this is enabled." + required: false diff --git a/src/index.js b/src/index.js index b53f621a9..763bce938 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,8 @@ module.exports = async function run() { wip, subjectPattern, subjectPatternError, + headerPattern, + headerPatternCorrespondence, validateSingleCommit, validateSingleCommitMatchesPrTitle, githubBaseUrl, @@ -66,7 +68,9 @@ module.exports = async function run() { scopes, requireScope, subjectPattern, - subjectPatternError + subjectPatternError, + headerPattern, + headerPatternCorrespondence }); if (validateSingleCommit) { @@ -105,7 +109,9 @@ module.exports = async function run() { scopes, requireScope, subjectPattern, - subjectPatternError + subjectPatternError, + headerPattern, + headerPatternCorrespondence }); } catch (error) { throw new Error( diff --git a/src/parseConfig.js b/src/parseConfig.js index 773b0d989..a3f8f93f0 100644 --- a/src/parseConfig.js +++ b/src/parseConfig.js @@ -28,6 +28,18 @@ module.exports = function parseConfig() { ); } + let headerPattern; + if (process.env.INPUT_HEADERPATTERN) { + headerPattern = ConfigParser.parseString(process.env.INPUT_HEADERPATTERN); + } + + let headerPatternCorrespondence; + if (process.env.INPUT_HEADERPATTERNCORRESPONDENCE) { + headerPatternCorrespondence = ConfigParser.parseString( + process.env.INPUT_HEADERPATTERNCORRESPONDENCE + ); + } + let wip; if (process.env.INPUT_WIP) { wip = ConfigParser.parseBoolean(process.env.INPUT_WIP); @@ -64,6 +76,8 @@ module.exports = function parseConfig() { wip, subjectPattern, subjectPatternError, + headerPattern, + headerPatternCorrespondence, validateSingleCommit, validateSingleCommitMatchesPrTitle, githubBaseUrl, diff --git a/src/validatePrTitle.js b/src/validatePrTitle.js index 5416ba101..b87f28dfd 100644 --- a/src/validatePrTitle.js +++ b/src/validatePrTitle.js @@ -7,11 +7,25 @@ const defaultTypes = Object.keys(conventionalCommitTypes.types); module.exports = async function validatePrTitle( prTitle, - {types, scopes, requireScope, subjectPattern, subjectPatternError} = {} + { + types, + scopes, + requireScope, + subjectPattern, + subjectPatternError, + headerPattern, + headerPatternCorrespondence + } = {} ) { if (!types) types = defaultTypes; const {parserOpts} = await conventionalCommitsConfig(); + if (headerPattern) { + parserOpts.headerPattern = headerPattern; + } + if (headerPatternCorrespondence) { + parserOpts.headerCorrespondence = headerPatternCorrespondence; + } const result = parser(prTitle, parserOpts); function printAvailableTypes() {