mirror of
https://github.com/leon-ai/leon.git
synced 2024-12-21 07:41:39 +03:00
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
import log from '@/helpers/log'
|
|
|
|
/**
|
|
* This script is executed after "git commit" or "git merge" (Git hook https://git-scm.com/docs/githooks#_commit_msg)
|
|
* it allows to ensure the authenticity of the commit messages
|
|
*/
|
|
log.info('Checking commit message...')
|
|
|
|
const commitEditMsgFile = '.git/COMMIT_EDITMSG'
|
|
|
|
if (fs.existsSync(commitEditMsgFile)) {
|
|
try {
|
|
const commitMessage = fs.readFileSync(commitEditMsgFile, 'utf8')
|
|
const packagesDir = 'packages'
|
|
const packages = fs.readdirSync(packagesDir)
|
|
.filter(entity =>
|
|
fs.statSync(path.join(packagesDir, entity)).isDirectory())
|
|
const packagesScopeString = packages.map((pkg, i) => {
|
|
if (packages.length === i + 1) return pkg
|
|
return `${pkg}|`
|
|
}).join('')
|
|
|
|
const regex = `(build|BREAKING|chore|docs|feat|fix|perf|refactor|style|test)(\\((web app|server|hotword|package\\/(${packagesScopeString})))?\\)?: .{1,50}` // eslint-disable-line no-useless-escape
|
|
|
|
if (commitMessage.match(regex) !== null) {
|
|
log.success('Commit message validated')
|
|
} else {
|
|
log.error(`Commit message does not match the format: ${regex}`)
|
|
process.exit(1)
|
|
}
|
|
} catch (e) {
|
|
log.error(e.message)
|
|
process.exit(1)
|
|
}
|
|
}
|