Skip to content

Commit

Permalink
feat: introduce allowed-commit-types input
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Nov 23, 2023
1 parent 0cd2831 commit aa06c90
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 1 addition & 17 deletions src/isValidCommitMesage.ts
Original file line number Diff line number Diff line change
@@ -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 ")) {
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit aa06c90

Please sign in to comment.