feat: introduce allowed-commit-types input

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

View file

@ -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

View file

@ -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 ")) {

View file

@ -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}`);