Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: show more info when verify commit fails #125

Merged
merged 2 commits into from
Apr 24, 2022

Conversation

Lsnsh
Copy link
Contributor

@Lsnsh Lsnsh commented Mar 29, 2022

背景

第一次使用 ant-design-pro 搭建项目,提交 commit 的时候提交失败

  • git commit -m "delete: i18n-删除所有语言资源文件,仅保留中英文"
 > running pre-commit hook: npm run precommit

> ant-design-pro@5.2.0 precommit
> lint-staged

ℹ No staged files found.
 > running commit-msg hook: fabric verify-commit

   ERROR  提交日志不符合规范

  合法的提交日志格式如下(emoji 和 模块可选填):

    
        💥 feat(模块): 添加了个很棒的功能
        🐛 fix(模块): 修复了一些 bug
        📝 docs(模块): 更新了一下文档
        🌷 UI(模块): 修改了一下样式
        🏰 chore(模块): 对脚手架做了些更改
        🌐 locale(模块): 为国际化做了微小的贡献
        See .github/commit-convention.md for more details.


commit-msg hook failed (add --no-verify to bypass)
"gitHooks": {
    "commit-msg": "fabric verify-commit"
}

发现项目默认会校验 commit message,但是从现有的提示中没有找到合适的 commit type(感觉这种情况,隔绝了很多想用校验,但是因为不了解相关规范,没法舒适使用,于是弃用的潜在用户),我其实也想干脆直接去掉校验算了,但是想想还是查了查,于是找到了这个仓库,以及对应负责校验的 verifyCommit.ts

通过阅读正则表达式,发现满足我的条件并且能通过校验的 commit message 得这样写:

  • git commit -m "delete: i18n-删除所有语言资源文件,仅保留中英文"
  • git commit -m "revert: locale: i18n-删除所有语言资源文件,仅保留中英文"

改动

为了方便用户快捷的找到合适的 commit type,写出通过校验的 commit message,做了如下改动:

  • 校验不通过时,显示更多提示信息(基本校验规则、其余 commit 类型)并微调排版
    • [<emoji>] <type>[<scope>]: <message>
  • 校验不通过时,显示详细的校验规则(增加 revert 相关的内容)
    • [<emoji>] [revert: ?]<type>[(scope)?]: <message>

测试/预览改动

"devDependencies": {
-  "@umijs/fabric": "^2.8.0",
+  "@umijs/fabric": "/Users/lsnsh/***/fork/fabric"
}

将改动运行测试脚本后,在自己项目中,改用绝对路径重新安装 @umijs/fabric,测试提交 commit 后,实际效果如下:

中文:

➜  *** git:(master) ✗ git commit -m "delete: i18n-删除所有语言资源文件,仅保留中英文"
 > running pre-commit hook: npm run precommit

> ant-design-pro@5.2.0 precommit
> lint-staged

ℹ No staged files found.
 > running commit-msg hook: fabric verify-commit

   ERROR  提交日志不符合规范

  合法的提交日志格式如下(emoji 和 模块可选填):

    
        [<emoji>] [revert: ?]<type>[(scope)?]: <message>

        💥 feat(模块): 添加了个很棒的功能
        🐛 fix(模块): 修复了一些 bug
        📝 docs(模块): 更新了一下文档
        🌷 UI(模块): 修改了一下样式
        🏰 chore(模块): 对脚手架做了些更改
        🌐 locale(模块): 为国际化做了微小的贡献

        其他提交类型: refactor, ⚡perf, workflow, build, CI, typos, tests, types, wip, release, dep

        See .github/commit-convention.md for more details.


commit-msg hook failed (add --no-verify to bypass)

英文:

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
 > running pre-commit hook: npm run precommit

> ant-design-pro@5.2.0 precommit
> lint-staged

ℹ No staged files found.
 > running commit-msg hook: fabric verify-commit

   ERROR  invalid commit message format.

  Proper commit message format is required for automated changelog generation. Examples:

    
        [<emoji>] [revert: ?]<type>[(scope)?]: <message>

        💥 feat(compiler): add 'comments' option
        🐛 fix(compiler): fix some bug
        📝 docs(compiler): add some docs
        🌷 UI(compiler): better styles
        🏰 chore(compiler): Made some changes to the scaffolding
        🌐 locale(compiler): Made a small contribution to internationalization

        Other commit types: refactor, ⚡perf, workflow, build, CI, typos, tests, types, wip, release, dep

        See .github/commit-convention.md for more details.


commit-msg hook failed (add --no-verify to bypass)

参考资料

@chenshuai2144 chenshuai2144 merged commit d739b70 into umijs:master Apr 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants