Last active
May 16, 2023 09:08
-
-
Save nflaig/48ea28e05d292b0eeb1493dd4110ce48 to your computer and use it in GitHub Desktop.
Conventional commit regex test cases
This file contains 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
function testCommit(commit) { | |
const conventionalCommit = commit.match(/^([a-z]+)(?:\((.*)\))?(?:(!))?: (.*)$/); | |
if (!conventionalCommit) { | |
console.log(`No match: ${commit}`); | |
return; | |
} | |
const [, type, scope, breaking, subject] = conventionalCommit; | |
console.log(`Type: ${type}`); | |
console.log(`Scope: ${scope}`); | |
console.log(`Breaking: ${breaking ? "Yes" : "No"}`); | |
console.log(`Subject: ${subject}`); | |
console.log("---"); | |
} | |
testCommit("feat(api)!: send an email to the customer when a product is shipped"); | |
testCommit("feat(EIP-4844): change related to an eip"); | |
testCommit("fix(server): handle null exception"); | |
testCommit("docs(readme): update installation guide"); | |
testCommit("chore(deps): update dependencies"); | |
testCommit("refactor(utils): improve code readability"); | |
testCommit("build(ci): add test script to CI pipeline"); | |
testCommit("style(css): fix indentation"); | |
testCommit("test(unit-tests): add more test cases"); | |
testCommit("refactor(reqresp)!: support byte based handlers (#123) (@abc)"); | |
testCommit("not a conventional commit"); // This should not match |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment