ramsey / conventional-commits
一个用于根据常规提交规范创建和验证提交信息的PHP库。包含CaptainHook操作!
Requires
- php: ^8.1
- composer-runtime-api: ^2.0
- ext-json: *
- composer/composer: ^2.4
- jawira/case-converter: ^3.5
- opis/json-schema: ^2.3
- symfony/console: ^6.0 || ^7.0
- symfony/filesystem: ^6.0 || ^7.0
Requires (Dev)
- captainhook/captainhook: ^5.15
- captainhook/plugin-composer: ^5.3
- ergebnis/composer-normalize: ^2.30
- hamcrest/hamcrest-php: ^2.0
- mockery/mockery: ^1.5
- php-parallel-lint/php-console-highlighter: ^1.0
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.10
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^10.1
- ramsey/coding-standard: ^2.2
- ramsey/composer-repl: ^1.4
- roave/security-advisories: dev-latest
- sebastianfeldmann/cli: ^3.4
- sebastianfeldmann/git: ^3.8
- spatie/phpunit-snapshot-assertions: ^5.1
- symfony/process: ^6.0 || ^7.0
Suggests
- captainhook/captainhook: Manage your project's Git hooks with CaptainHook, and use ramsey/conventional-commits in your commit-msg and prepare-commit-msg hooks.
README
一个用于创建和验证提交信息的PHP库。
关于
ramsey/conventional-commits是一个根据常规提交规范创建和验证提交信息的PHP库。它还包括一个CaptainHook操作!
本项目遵循行为准则。通过参与本项目及其社区,您应遵守此行为准则。
安装
使用Composer将此包作为开发依赖项安装。
composer require --dev ramsey/conventional-commits
用法
要使用conventional-commits控制台命令来帮助您根据常规提交准备提交信息,请在您的控制台中输入以下命令
./vendor/bin/conventional-commits prepare
您也可以使用以下命令验证提交信息
./vendor/bin/conventional-commits validate "[commit message]"
如果您在命令行中没有提供提交信息,则命令将提示您输入。
要查看控制台命令的所有功能,请输入
./vendor/bin/conventional-commits
CaptainHook操作
要使用ramsey/conventional-commits与CaptainHook作为您的commit-msg和/或prepare-commit-msg Git钩子的一部分,请确保将CaptainHook作为开发依赖项引入。
请参阅CaptainHook文档以获取有关安装和配置CaptainHook的更多信息。
验证提交信息
要使用CaptainHook操作根据常规提交规范验证提交信息,请将以下内容添加到您的captainhook.json文件中的commit-msg属性中
{
"commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit"
}
]
}
}
准备提交信息
您可以将此库设置为在您使用git commit时提示您准备提交信息!
要使用CaptainHook操作根据常规提交规范准备提交信息,请将以下内容添加到您的captainhook.json文件中的prepare-commit-msg属性中
{
"prepare-commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\Ramsey\\CaptainHook\\PrepareConventionalCommit"
}
]
}
}
配置
配置ramsey/conventional-commits提供了对提交信息的一些更多方面的控制,例如字母大小写(即小写,大写)、允许的类型和范围、必需的页脚等。
我们在以下两个地方寻找配置
composer.jsoncaptainhook.json
⚠️ 请注意:如果您的
composer.json文件不在与vendor/目录相同的目录中,我们可能难以找到它。请随时提交问题,我们将与您合作以查找解决方案。
配置属性
ramsey/conventional-commits的配置由以下属性组成
当指定配置时,如果您想使用属性的默认行为,则无需在配置中列出该属性。
支持的字母大小写为
在composer.json中的配置
如果您选择在composer.json中放置您的配置,请将其放在extra属性中,在ramsey/conventional-commits命名空间下,如下所示
{
"extra": {
"ramsey/conventional-commits": {
"config": {
"typeCase": null,
"types": [],
"scopeCase": null,
"scopeRequired": false,
"scopes": [],
"descriptionCase": null,
"descriptionEndMark": null,
"bodyRequired": false,
"bodyWrapWidth": null,
"requiredFooters": []
}
}
}
}
📝 本示例中的属性表示默认值。
captainhook.json 中的配置
如果您选择将配置放在 captainhook.json 中,您必须为每个配置的动作提供它,例如
{
"commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit",
"options": {
"config": {
"typeCase": null,
"types": [],
"scopeCase": null,
"scopeRequired": false,
"scopes": [],
"descriptionCase": null,
"descriptionEndMark": null,
"bodyRequired": false,
"bodyWrapWidth": null,
"requiredFooters": []
}
}
}
]
},
"prepare-commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\Ramsey\\CaptainHook\\PrepareConventionalCommit",
"options": {
"config": {
"typeCase": null,
"types": [],
"scopeCase": null,
"scopeRequired": false,
"scopes": [],
"descriptionCase": null,
"descriptionEndMark": null,
"bodyRequired": false,
"bodyWrapWidth": null,
"requiredFooters": []
}
}
}
]
}
}
然而,如果您在 composer.json 中提供了配置,则无需在 captainhook.json 中也提供。
🚨 如果使用 Captain Hook 的 Git 提交钩子功能,
captainhook.json中提供的任何配置将覆盖composer.json中的配置。⚠️ 当使用独立命令(即
./vendor/bin/conventional-commits)时,除非提供--config选项,否则只有composer.json中的配置将生效。
单独的文件中的配置
您还可以将配置存储在单独的文件中。例如,您可能将其存储在 conventional-commits.json 中,如下所示
{
"typeCase": "kebab",
"types": [
"ci",
"deps",
"docs",
"refactor",
"style",
"test"
],
"scopeCase": "kebab",
"scopeRequired": false,
"scopes": [],
"descriptionCase": "lower",
"descriptionEndMark": "",
"bodyRequired": true,
"bodyWrapWidth": 72,
"requiredFooters": ["Signed-off-by"]
}
当存储在单独的文件中时,除非您告诉我们,否则我们不知道在哪里寻找您的配置,因此您仍然必须在 composer.json 或 captainhook.json 中提供一小部分配置,以便我们能够找到它。
这是在 composer.json 中的样子
{
"extra": {
"ramsey/conventional-commits": {
"configFile": "./conventional-commits.json"
}
}
}
这是在 captainhook.json 中的样子
{
"commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit",
"options": {
"configFile": "./conventional-commits.json"
}
}
]
},
"prepare-commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\Ramsey\\CaptainHook\\PrepareConventionalCommit",
"options": {
"configFile": "./conventional-commits.json"
}
}
]
}
}
贡献
欢迎贡献!要贡献,请熟悉 CONTRIBUTING.md。
协调披露
保护用户信息的安全和完整是我们的首要任务,我们欢迎外部安全研究者的贡献。如果您认为您在此存储库维护的软件中发现了安全漏洞,请阅读 SECURITY.md 以获取提交漏洞报告的说明。
版权和许可证
ramsey/conventional-commits 库版权 © Ben Ramsey,并许可在 MIT 许可证(MIT)的条款下使用。有关更多信息,请参阅 LICENSE。