1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-08-16 21:50:33 +03:00
leon/scripts/commit-msg.js

35 lines
1.0 KiB
JavaScript
Raw Permalink 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
*/
2023-04-02 21:34:50 +03:00
;(async () => {
LogHelper.info('Checking commit message...')
2021-12-27 17:57:06 +03:00
2023-04-02 21:34:50 +03:00
const commitEditMsgFile = '.git/COMMIT_EDITMSG'
2021-12-27 17:57:06 +03:00
2023-04-02 21:34:50 +03:00
if (fs.existsSync(commitEditMsgFile)) {
try {
const commitMessage = await fs.promises.readFile(
commitEditMsgFile,
'utf8'
)
const regex =
'(build|BREAKING|chore|ci|docs|feat|fix|perf|refactor|style|test)(\\((web app|scripts|server|hotword|python tcp server|llm tcp server|bridge\\/(python|nodejs)|skill\\/([\\w-]+)))?\\)?: .{1,50}'
2021-12-27 17:57:06 +03:00
2023-04-02 21:34:50 +03:00
if (commitMessage.match(regex) !== null) {
LogHelper.success('Commit message validated')
} else {
LogHelper.error(`Commit message does not match the format: ${regex}`)
process.exit(1)
}
} catch (e) {
LogHelper.error(e.message)
2021-12-27 17:57:06 +03:00
process.exit(1)
}
}
2023-04-02 21:34:50 +03:00
})()