forked from leon-ai/leon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-message.js
More file actions
38 lines (32 loc) · 1.24 KB
/
commit-message.js
File metadata and controls
38 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
}
}