1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-09-11 10:25:40 +03:00
leon/scripts/commit-msg.js
2022-09-03 19:12:41 +08:00

30 lines
908 B
JavaScript

import fs from 'fs'
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 ensures the authenticity of commit messages
*/
log.info('Checking commit message...')
const commitEditMsgFile = '.git/COMMIT_EDITMSG'
if (fs.existsSync(commitEditMsgFile)) {
try {
const commitMessage = fs.readFileSync(commitEditMsgFile, 'utf8')
const regex =
'(build|BREAKING|chore|ci|docs|feat|fix|perf|refactor|style|test)(\\((web app|docker|server|hotword|skill\\/([\\w-]+)))?\\)?: .{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)
}
}