feat: check message when commit (#8166)

This commit is contained in:
三咲智子 2022-06-08 15:17:04 +08:00 committed by GitHub
parent 4484d07d76
commit 069021e26a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 119 additions and 114 deletions

4
.husky/commit-msg Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
pnpm exec commitlint --config commitlint.config.js --edit "${1}"

View File

@ -1,4 +0,0 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run test

View File

@ -1,110 +1,3 @@
'use strict' // commitlint uses `ts-node` to load typescript config, it's too slow. So we replace it with `esbuild`.
const { execSync } = require('child_process') require('@esbuild-kit/cjs-loader')
const fg = require('fast-glob') module.exports = require('./commitlint.config.ts').default
const getPackages = (packagePath) =>
fg.sync('*', { cwd: packagePath, onlyDirectories: true })
const scopes = [
...getPackages('packages'),
...getPackages('internal'),
'docs',
'play',
'project',
'core',
'style',
'ci',
'dev',
'deploy',
'other',
'typography',
'color',
'border',
'var',
'ssr',
]
const gitStatus = execSync('git status --porcelain || true')
.toString()
.trim()
.split('\n')
const scopeComplete = gitStatus
.find((r) => ~r.indexOf('M packages'))
?.replace(/\//g, '%%')
?.match(/packages%%((\w|-)*)/)?.[1]
const subjectComplete = gitStatus
.find((r) => ~r.indexOf('M packages/components'))
?.replace(/\//g, '%%')
?.match(/packages%%components%%((\w|-)*)/)?.[1]
module.exports = {
rules: {
/**
* type[scope]: [function] description
* ^^^^^
*/
'scope-enum': [2, 'always', scopes],
/**
* type[scope]: [function] description
*
* ^^^^^^^^^^^^^^ empty line.
* - Something here
*/
'body-leading-blank': [1, 'always'],
/**
* type[scope]: [function] description
*
* - something here
*
* ^^^^^^^^^^^^^^
*/
'footer-leading-blank': [1, 'always'],
/**
* type[scope]: [function] description [No more than 72 characters]
* ^^^^^
*/
'header-max-length': [2, 'always', 72],
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [
1,
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
/**
* type[scope]: [function] description
* ^^^^
*/
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'release',
'style',
'test',
'improvement',
],
],
},
prompt: {
defaultScope: scopeComplete,
customScopesAlign: !scopeComplete ? 'top' : 'bottom',
defaultSubject: subjectComplete && `[${subjectComplete}] `,
allowCustomIssuePrefixs: false,
allowEmptyIssuePrefixs: false,
},
}

109
commitlint.config.ts Normal file
View File

@ -0,0 +1,109 @@
import { execSync } from 'child_process'
import fg from 'fast-glob'
const getPackages = (packagePath) =>
fg.sync('*', { cwd: packagePath, onlyDirectories: true })
const scopes = [
...getPackages('packages'),
...getPackages('internal'),
'docs',
'play',
'project',
'core',
'style',
'ci',
'dev',
'deploy',
'other',
'typography',
'color',
'border',
'var',
'ssr',
]
const gitStatus = execSync('git status --porcelain || true')
.toString()
.trim()
.split('\n')
const scopeComplete = gitStatus
.find((r) => ~r.indexOf('M packages'))
?.replace(/\//g, '%%')
?.match(/packages%%((\w|-)*)/)?.[1]
const subjectComplete = gitStatus
.find((r) => ~r.indexOf('M packages/components'))
?.replace(/\//g, '%%')
?.match(/packages%%components%%((\w|-)*)/)?.[1]
export default {
rules: {
/**
* type[scope]: [function] description
* ^^^^^
*/
'scope-enum': [2, 'always', scopes],
/**
* type[scope]: [function] description
*
* ^^^^^^^^^^^^^^ empty line.
* - Something here
*/
'body-leading-blank': [1, 'always'],
/**
* type[scope]: [function] description
*
* - something here
*
* ^^^^^^^^^^^^^^
*/
'footer-leading-blank': [1, 'always'],
/**
* type[scope]: [function] description [No more than 72 characters]
* ^^^^^
*/
'header-max-length': [2, 'always', 72],
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [
1,
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
/**
* type[scope]: [function] description
* ^^^^
*/
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'release',
'style',
'test',
'improvement',
],
],
},
prompt: {
defaultScope: scopeComplete,
customScopesAlign: !scopeComplete ? 'top' : 'bottom',
defaultSubject: subjectComplete && `[${subjectComplete}] `,
allowCustomIssuePrefixs: false,
allowEmptyIssuePrefixs: false,
},
}

View File

@ -74,6 +74,7 @@
"@element-plus/build": "workspace:^0.0.1", "@element-plus/build": "workspace:^0.0.1",
"@element-plus/build-utils": "workspace:^0.0.1", "@element-plus/build-utils": "workspace:^0.0.1",
"@element-plus/eslint-config": "workspace:*", "@element-plus/eslint-config": "workspace:*",
"@esbuild-kit/cjs-loader": "^2.0.1",
"@pnpm/find-workspace-packages": "^4.0.10", "@pnpm/find-workspace-packages": "^4.0.10",
"@pnpm/logger": "^4.0.0", "@pnpm/logger": "^4.0.0",
"@pnpm/types": "^8.0.1", "@pnpm/types": "^8.0.1",

View File

@ -19,6 +19,7 @@ importers:
'@element-plus/theme-chalk': workspace:* '@element-plus/theme-chalk': workspace:*
'@element-plus/tokens': workspace:* '@element-plus/tokens': workspace:*
'@element-plus/utils': workspace:* '@element-plus/utils': workspace:*
'@esbuild-kit/cjs-loader': ^2.0.1
'@floating-ui/dom': ^0.5.2 '@floating-ui/dom': ^0.5.2
'@pnpm/find-workspace-packages': ^4.0.10 '@pnpm/find-workspace-packages': ^4.0.10
'@pnpm/logger': ^4.0.0 '@pnpm/logger': ^4.0.0
@ -106,6 +107,7 @@ importers:
'@element-plus/build': link:internal/build '@element-plus/build': link:internal/build
'@element-plus/build-utils': link:internal/build-utils '@element-plus/build-utils': link:internal/build-utils
'@element-plus/eslint-config': link:internal/eslint-config '@element-plus/eslint-config': link:internal/eslint-config
'@esbuild-kit/cjs-loader': 2.0.1
'@pnpm/find-workspace-packages': 4.0.10_@pnpm+logger@4.0.0 '@pnpm/find-workspace-packages': 4.0.10_@pnpm+logger@4.0.0
'@pnpm/logger': 4.0.0 '@pnpm/logger': 4.0.0
'@pnpm/types': 8.0.1 '@pnpm/types': 8.0.1