Chinese readme | English readme |
---|---|
此專案使用參考 angular commit message guidelines 所定的規範
驗證以下 commit 格式:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
License | Release | Download | Issues | Wiki |
---|---|---|---|---|
-
linux
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs
- check
node --version npm --version
sudo npm install -g pkg
npm i
npm test
cd git-commit-msg-validate mkdir build cd build pkg ../
- 於你的 repository root 新增 package.json :
{
"//": "repository Config",
"name":"Your Project Name",
"description": "Your description",
"homepage": "",
"repository": {
"type": "git",
"url": "http://your_repo.git"
}
}
- 於你的 repository root 新增 .vcmrc :
e.g.
{
"helpMessage": "\n請協助完善 Commit 資訊, 必要時請協助維護 .vcmrc 檔案的 types or scope[allowed] 項目!!\n",
"scopesetting": {
"required": false,
"validate": true,
"multiple": false
},
"maxSubjectLength": 100,
"warnOnFail": false,
"autoFix": true,
"blanklineErrorMsg": "第二行必須為空白行, 用於區分主旨與內文",
"patternErrorMsg": "格式不符,請使用以下格式:\n <type>(<scope>):<空格>新增/修改/修正/刪除/重構/優化 <subject> ",
"scopes": {
"Docs": "文件相關",
"Tool": "工具程式相關",
"Shell": "Shell Script相關",
"QtConfig": "Qt 專案配置相關",
"GitConfig": "Git 板控配置相關"
},
"scopeErrorMsg": "scope 無效,請使用以下 scope: ",
"types": {
"fix": "Bug Fixes",
"feat": "New Features",
"release": "Release Version",
"refactor": "Refactors",
"merge": "Branch merge",
"revert": "Reverts",
"docs": "Documentation Changes",
"perf": "Performance Improvements",
"style": "Code Style Changes",
"misc": "Miscellaneous",
"build": "Build System / Dependencies",
"ci": "Continuous Integration",
"test": "Tests"
},
"typePatternErrorMsg": "type 無效,請使用以下type: ",
"subjectPattern": "新增|修改|修正|刪除|重構|合併|優化",
"subjectPatternErrorMsg": "subject 無效, 請確認是否有包含以下其中字串: "
}
格式如下:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
commit 類別
請參考資訊:
angular commit message guidelines
type 欄位驗證錯誤訊息
commit 作用範圍
format:
"scopes": {
"key": "value"
}
example:
"scopes": {
"Docs": "文件相關",
"Tool": "工具程式相關",
"Shell": "Shell Script相關",
"QtConfig": "Qt 專案配置相關",
"GitConfig": "Git 板控配置相關"
}
scope 欄位驗證錯誤訊息
commit 主旨 (RegExp match)
example:
"subjectPattern": "新增|修改|修正|刪除|重構|合併|優化",
subject 欄位驗證錯誤訊息
<BLANK LINE>
欄位驗證錯誤訊息
- required
- 設定是否必須輸入 scope 欄位, default: false
- validate
- 是否驗證 scope 欄位, default: true
- multiple
- 是否驗證多個 scope 欄位, default: false
設定是否忽略錯誤只顯示錯誤訊息, default: false
主旨最大字串長度
提示訊息
example:
var validateMessage = require('validate-commit-msg');
var valid = validateMessage('chore(index): an example commit message');
// valid = true
#!/usr/bin/env bash
############################################################
# Variable
############################################################
os_version=$(uname -s)
dir=`pwd`
###############################################################
# Function
###############################################################
## Commit 格式校驗 ##
validateCommitMsg(){
echo "run validateCommitMsg..."
cmd_linux=$dir/.githooks/validate-commit-msg-linux
cmd_windows=$dir/.githooks/validate-commit-msg-win.exe
if [[ $os_version =~ "Linux" ]]; then
echo "linux"
$cmd_linux "`cat .git/COMMIT_EDITMSG`"
elif [[ $os_version =~ "MINGW" ]]; then
echo "Windows"
$cmd_windows "`cat .git/COMMIT_EDITMSG`"
elif [[ $os_version =~ "Darwin" ]]; then
echo "Mac OS X"
$cmd_linux "`cat .git/COMMIT_EDITMSG`"
fi
}
###############################################################
# Main Content
###############################################################
## validateCommitMsg ##
validateCommitMsg
example:
validate-commit-msg "$(git log -1 --pretty=%B)"
範例:
my-lerna-repo/
package.json
packages/
package-1/
package.json
package-2/
package.json
packages.json 設定
e.g.
{
"config": {
"validate-commit-msg": {
"scope": {
"required": true,
"allowed": ["package-1", "package-2"],
"validate": true,
"multiple": true
},
}
}
}