From b1c8a44db34ec59a61fd0403dca2bae9f6470507 Mon Sep 17 00:00:00 2001 From: adrians5j Date: Thu, 23 Nov 2023 22:22:12 +0100 Subject: [PATCH] feat: introduce `allowed-commit-types` input --- action.yml | 5 +++++ src/isValidCommitMesage.ts | 18 +----------------- src/main.ts | 5 ++++- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index 4a4d1cb..ca54951 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,11 @@ inputs: GITHUB_TOKEN: description: 'GitHub token' required: false + allowed-commit-types: + description: 'Specify a comma separated list of allowed commit types' + default: 'feat,fix,docs,style,refactor,test,build,perf,ci,chore,revert,merge,wip' + required: false + runs: using: node16 main: dist/main/index.js diff --git a/src/isValidCommitMesage.ts b/src/isValidCommitMesage.ts index edd8578..f192a4e 100644 --- a/src/isValidCommitMesage.ts +++ b/src/isValidCommitMesage.ts @@ -1,20 +1,4 @@ -const DEFAULT_COMMIT_TYPES = [ - "feat", - "fix", - "docs", - "style", - "refactor", - "test", - "build", - "perf", - "ci", - "chore", - "revert", - "merge", - "wip", -]; - -const isValidCommitMessage = (message, availableTypes = DEFAULT_COMMIT_TYPES): boolean => { +const isValidCommitMessage = (message: string, availableTypes: string[]): boolean => { // Exceptions. // This is a message that's auto-generated by git. Can't do much about it unfortunately. Let's allow it. if (message.startsWith("Merge ") || message.startsWith("Revert ")) { diff --git a/src/main.ts b/src/main.ts index b1ec4bd..0d15448 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,7 +19,10 @@ async function run() { core.startGroup("Commit messages:"); for (let i = 0; i < extractedCommits.length; i++) { let commit = extractedCommits[i]; - if (isValidCommitMessage(commit.message)) { + + const allowedCommitTypes = core.getInput("allowed-commit-types").split(","); + + if (isValidCommitMessage(commit.message, allowedCommitTypes)) { core.info(`✅ ${commit.message}`); } else { core.info(`🚩 ${commit.message}`);