1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-09-11 18:27:21 +03:00
leon/scripts/commit-msg.js

30 lines
938 B
JavaScript
Raw Normal View History

import fs from 'node:fs'
2021-12-27 17:57:06 +03:00
import { LogHelper } from '@/helpers/log-helper'
2021-12-27 17:57:06 +03:00
/**
* 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
*/
LogHelper.info('Checking commit message...')
2021-12-27 17:57:06 +03:00
const commitEditMsgFile = '.git/COMMIT_EDITMSG'
if (fs.existsSync(commitEditMsgFile)) {
try {
const commitMessage = fs.readFileSync(commitEditMsgFile, 'utf8')
2022-09-03 14:12:41 +03:00
const regex =
2022-10-06 11:27:20 +03:00
'(build|BREAKING|chore|ci|docs|feat|fix|perf|refactor|style|test)(\\((web app|docker|server|hotword|tcp server|python bridge|skill\\/([\\w-]+)))?\\)?: .{1,50}'
2021-12-27 17:57:06 +03:00
if (commitMessage.match(regex) !== null) {
LogHelper.success('Commit message validated')
2021-12-27 17:57:06 +03:00
} else {
LogHelper.error(`Commit message does not match the format: ${regex}`)
2021-12-27 17:57:06 +03:00
process.exit(1)
}
} catch (e) {
LogHelper.error(e.message)
2021-12-27 17:57:06 +03:00
process.exit(1)
}
}