Last active
May 1, 2025 15:07
-
-
Save lynsei/1ef32bd392816c4fde4ca848fbfdc8ce to your computer and use it in GitHub Desktop.
[commit-msg] #deno validation for #lefthook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S deno run --allow-read | |
/** | |
* @file .lefthook.commit.ts | |
* @description This script validates commit messages based on a specific format. | |
* @author Lynsei H | |
* @usage deno run -A ./src/.lefthook.commit.ts "feature/story_89: This is cool!" | |
* @returns true if commit is invalid, otherwise false | |
*/ | |
const VALID_TYPES = [ | |
"feature", "task", "bug", "patch", "spike", | |
"docs", "fmt", "enhancement", "series", "epic" | |
]; | |
const COMMIT_MSG_FILE = Deno.args[0] || ".git/COMMIT_EDITMSG"; | |
const message = Deno.args[0].trim(); | |
const regex = /^([a-z]+)\/story_(\d+):\s.+$/; | |
const match = message.match(regex); | |
let err = 'false'; // Declare err outside the blocks | |
if (match) { | |
const [_, type] = match; | |
if (!VALID_TYPES.includes(type)) { | |
err = 'true'; | |
} | |
} else { | |
err = 'true'; | |
} | |
// All validations passed | |
console.log(err); | |
Deno.exit(0); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment