2022-09-26 18:28:25 +03:00
|
|
|
import fs from 'node:fs'
|
2021-12-27 17:57:06 +03:00
|
|
|
|
2022-09-26 16:29:56 +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 =
|
2024-02-14 04:45:26 +03:00
|
|
|
'(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
|
|
|
})()
|