// Conventional Commits parsing shared by the commit-msg lint // (lint-commit-msg.mjs) and the release-time versioner (version-bump.mjs). export const TYPES = ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'] export const HEADER = new RegExp(`^(${TYPES.join('|')})(\\([^()]+\\))?(!)?: .+`) // Messages git writes for us keep whatever shape git gave them. export const GIT_SHAPES = /^(Merge |Revert |fixup! |squash! |amend! )/ // Semver bump for one already-matched header: breaking -> major, feat -> // minor, fix/perf -> patch, anything else -> null. `lines` is the whole // message, for BREAKING CHANGE footers. export function bumpFor(header, lines) { const [, type, , bang] = HEADER.exec(header) const breaking = bang === '!' || lines.some((line) => /^BREAKING[- ]CHANGE: /.test(line)) return breaking ? 'major' : type === 'feat' ? 'minor' : type === 'fix' || type === 'perf' ? 'patch' : null }