Skip to content

Commit

Permalink
commit-lint支持gitHooks
Browse files Browse the repository at this point in the history
  • Loading branch information
xuasir committed Jan 29, 2021
1 parent f5e5df8 commit eae1e4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/cli-plugin-command-commit-lint/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const HuskyGitParamsEnv = 'HUSKY_GIT_PARAMS'
export const GitParamsEnv = 'GIT_PARAMS'

export const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|style|build|chore|refactor|ci|wip|breaking change)(\(.+\))?: .{1,50}/
export const mergeRE = /Merge /
14 changes: 9 additions & 5 deletions packages/cli-plugin-command-commit-lint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IPluginAPI } from '@xus/cli'
import { HuskyGitParamsEnv, commitRE, mergeRE } from './constants'
import { HuskyGitParamsEnv, GitParamsEnv, commitRE, mergeRE } from './constants'
import { readFileSync } from 'fs-extra'
import chalk from 'chalk'

Expand All @@ -11,12 +11,16 @@ export default function (api: IPluginAPI): void {
desc: 'help you to validate commit message'
},
() => {
const gitParams = api.EnvManager.getEnv(HuskyGitParamsEnv)
if (gitParams) {
const commitMsg = readFileSync(gitParams, 'utf-8').trim()
const gitMsgPath = api.EnvManager.getEnv(GitParamsEnv)
const huskyMsgPath = api.EnvManager.getEnv(HuskyGitParamsEnv)
const msgPath = gitMsgPath || huskyMsgPath
if (msgPath) {
const commitMsg = readFileSync(msgPath, 'utf-8')
.trim()
.replace(/# .*/, ' ')
if (!commitRE.test(commitMsg) && !mergeRE.test(commitMsg)) {
console.info(`invalid commit message:
"${chalk.red(commitMsg)}".
"${chalk.red(commitMsg)}".
Proper commit message format is required for automated changelog generation.
Expand Down

0 comments on commit eae1e4b

Please sign in to comment.