feat: introduce allowed-commit-types input

This commit is contained in:
adrians5j 2023-11-23 22:22:12 +01:00
parent 0cd283198a
commit b1c8a44db3
3 changed files with 10 additions and 18 deletions

View file

@ -4,6 +4,11 @@ inputs:
GITHUB_TOKEN: GITHUB_TOKEN:
description: 'GitHub token' description: 'GitHub token'
required: false 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: runs:
using: node16 using: node16
main: dist/main/index.js main: dist/main/index.js

View file

@ -1,20 +1,4 @@
const DEFAULT_COMMIT_TYPES = [ const isValidCommitMessage = (message: string, availableTypes: string[]): boolean => {
"feat",
"fix",
"docs",
"style",
"refactor",
"test",
"build",
"perf",
"ci",
"chore",
"revert",
"merge",
"wip",
];
const isValidCommitMessage = (message, availableTypes = DEFAULT_COMMIT_TYPES): boolean => {
// Exceptions. // Exceptions.
// This is a message that's auto-generated by git. Can't do much about it unfortunately. Let's allow it. // 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 ")) { if (message.startsWith("Merge ") || message.startsWith("Revert ")) {

View file

@ -19,7 +19,10 @@ async function run() {
core.startGroup("Commit messages:"); core.startGroup("Commit messages:");
for (let i = 0; i < extractedCommits.length; i++) { for (let i = 0; i < extractedCommits.length; i++) {
let commit = extractedCommits[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}`); core.info(`${commit.message}`);
} else { } else {
core.info(`🚩 ${commit.message}`); core.info(`🚩 ${commit.message}`);