当前位置: 首页 > 后端技术 > Node.js

cz-git使用技巧——让gitcommit不再麻烦

时间:2023-04-03 11:04:40 Node.js

什么是commitizen:基于Node.js的gitcommit命令行工具,帮助生成标准化规范化的commit信息。什么是适配器(adapter):一个替代commitizen命令行工具的交互式插件。今天终于完成了cz-git文档:http://cz-git.qbenben.com/,欢迎查看使用。让我介绍一些使用cz-git的技巧。Scopes通常在commitmessage中代表这个文档这里通常有两个范围:项目代码层面,比如你用yarn配合lerna或者用pnpm管理monorepo项目业务层面,比如(account)账户系统相关,(comment)commentsystemrelated...project在代码层面,如果你使用monorepo包作为范围,你可以这样定义//.commitlintrc.jsconstfs=require('fs')constpath=require('path')constpackages=fs.readdirSync(path.resolve(__dirname,'packages'))module.exports={prompt:{scopes:[...packages]}}当然,如果你使用commitlint规则定义scope-enum,它将自动导入。//.commitlintrc.jsconstfs=require('fs')constpath=require('path')constpackages=fs.readdirSync(path.resolve(__dirname,'packages'))module.exports={规则:{"scope-enum":[2,"always",[...packages]]}};项目业务级别//.commitlintrc.jsconstfs=require('fs')constpath=require('path')constpackages=fs.readdirSync(path.resolve(__dirname,'packages'))module.exports={prompt:{scopes:["home","account","comment"]}}当然如果你想给模块作用域自定义添加命令行显示的描述信息可以使用name和value属性来定义//.commitlintrc.jsconstfs=require('fs')constpath=require('path')constpackages=fs.readdirSync(path.resolve(__dirname,'packages'))module.exports={提示:{范围:[{value:"home",name:"home:主页相关"},{value:"account",name:"account:账户相关"},{value:"comment",name:"comment:评论相关"},]}}issuePref如果ixs国内用户使用Gitee作为项目管理,那么可以使用该工具通过commitmessage更改issue状态详情:giteeCommit通过设置taskstatus命令与Issue关联,即issue的别名状态变化,通过选择别名输入问题编号,可以很好的关联问题管理//.commitlintrc.jsmodule.exports={prompt:{issuePrefixs:[//@see:https://gitee.com/help/articles/4141#article-header2{value:"wip",name:"wip:将任务状态更改为进行中"},{value:"finish",name:"finish:更改状态ofthetasktopending"}]}}defaultIssues自动获取commit关联的issue,github的issue号一般是一个数字,而gitee有点反人类,这样每次commit的时候,如果要关联issue号码,我需要复制粘贴分行名称或者去网页找。如果我们的分支名有一套规范,比如fix/issue_I72636_qb,我可以这样处理:使用Node的execSync在运行时通过命令获取分支名,然后对获取到的字符串进行处理。然后我们使用defaultIssues属性传入并使用。我们只需要按下键。输出IssueNumber,方便我们截取??IssueNumber减少重复工作//.commitlintrc.jsconst{execSync}=require('child_process');//@tip:gitbranchname=feature/33=>autogetdefaultIssues=#33constissue=execSync('gitrev-parse--abbrev-refHEAD').toString().trim().split("_")[1]//@tip:monorepodynamicgetname/**@type{import('cz-git').UserConfig}*cli很符合你或团队的习惯,欢迎分享~我的开发历程:https://www.qbenben.com/post/...原文档链接:https://cz-git.qbenben.com/zh..github地址(欢迎??star??):https://github.com/Zhengqbbb/...