Skip to content

Instantly share code, notes, and snippets.

@nflaig
Last active May 16, 2023 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nflaig/48ea28e05d292b0eeb1493dd4110ce48 to your computer and use it in GitHub Desktop.
Save nflaig/48ea28e05d292b0eeb1493dd4110ce48 to your computer and use it in GitHub Desktop.
Conventional commit regex test cases
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