purplebooth/git-lint-validators

此包已被废弃,不再维护。作者建议使用sebastianfeldmann/captainhook包。

检查git提交

安装: 840

依赖: 1

建议: 0

安全: 0

星星: 26

观察者: 2

分支: 11

开放问题: 2

类型:项目

v1.2.0 2016-09-02 21:43 UTC

This package is not auto-updated.

Last update: 2022-02-01 13:00:22 UTC


README

此包已被废弃,不再维护。作者建议使用sebastianfeldmann/captainhook包。

Git Lint

Scrutinizer Code Quality Build Status Dependency Status Latest Stable Version License

此项目旨在确保您向存储库提交的提交遵循git编码风格。这仅仅是基本的验证器。

它们测试的标准是Chris Beams所描述的

它实施的验证包括

  • 将主题与正文通过空行分开
  • 限制主题行长度为50个字符(软限制,硬限制为69个字符)
  • 大写主题行
  • 主题行不以句号结尾
  • 在72个字符处包装正文

入门

先决条件

您需要安装

  • PHP(最低7.0版本)

安装

composer require --dev PurpleBooth/git-lint-validators

使用

工具

您可以通过将其用作git提交钩子来尝试这个库。

Git钩子安装

使用install-git-hook Composer脚本来安装钩子。现有的钩子将被备份到.git/hooks/commit-msg.bak

composer install-git-hook

它也相当可定制,以下是一些选项

$ vendor/bin/git-lint-validators help git-lint-validator:hook
Usage:
  git-lint-validator:hook [options] [--] <commit-message-file>

Arguments:
  commit-message-file                Path to commit message file

Options:
  -i, --ignore[=IGNORE]              Ignore a commit message that matches this pattern and don't test it [default: ["/^Merge branch/"]] (multiple values allowed)
  -c, --comment-char[=COMMENT-CHAR]  Ignore lines that are prefixed with this character [default: "#"]
  -h, --help                         Display this help message
  -q, --quiet                        Do not output any message
  -V, --version                      Display this application version
      --ansi                         Force ANSI output
      --no-ansi                      Disable ANSI output
  -n, --no-interaction               Do not ask any interactive question
  -v|vv|vvv, --verbose               Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
 Check your commit messages to ensure they follow the guidelines described by Chris Beams.
 To enable the Git hook in your project run 'composer install-git-hook.'


 Here are some good articles on commit message style:

 * http://chris.beams.io/posts/git-commit/
 * https://git-scm.cn/book/ch5-2.html#Commit-Guidelines
 * https://github.com/blog/926-shiny-new-commit-styles


运行时输出


$ git commit


 [ERROR] Incorrectly formatted commit message


 * Please limit the body line length of the commit message to 72 characters (http://chris.beams.io/posts/git-commit/#wrap-72)

Your Commit Message
-------------------

 Add commit message to output of hook

 It can be frustrating if you've lost a large git commit message because it
 doesn't match the style guide. This will add a little message including
 your commit details
 # Please enter the commit message for your changes. Lines starting
 # with '#' will be ignored, and an empty message aborts the commit.
 # On branch added-original-commit-message-to-hook
 # Changes to be committed:
 #	modified:   src/PurpleBooth/GitLintValidators/Command/Hook.php
 #



 [WARNING] A commit has not been created

安装Git提交消息模板

使用install-git-commit-message-template Composer脚本来安装和配置一个遵循Chris Beams规则提交消息模板。提交消息模板将被写入到.git/.gitmessage,并在执行不带消息选项的git commit时使用。

composer install-git-commit-message-template

您可以使用整个库

<?php

$validatorFactory = new ValidatorFactoryImplementation();
$validators       = $validatorFactory->getMessageValidator();

$message
    = <<<MESSAGE
This is an example title

This is a message body. This is another part of the body.
MESSAGE;

$exampleMessage = new MessageImplementation("exampleSha", $message);

$validators->validate($exampleMessage);
// -> Message Object will now have a Status objects set on them

或者您也可以单独使用验证器

<?php

new ValidateMessageImplementation(
    [
        new CapitalizeTheSubjectLineValidator(),
        new DoNotEndTheSubjectLineWithAPeriodValidator(),
    ]
);

$message
    = <<<MESSAGE
This is an example title

This is a message body. This is another part of the body.
MESSAGE;

$exampleMessage = new MessageImplementation("exampleSha", $message);

$messageValidator->validate($exampleMessage);
// -> Message Object will now have a Status objects set on them

请依赖于接口而不是具体实现。具体实现可能会更改而不会导致BC中断,接口的更改将导致主要版本号的增加,表示BC中断。

运行测试

首先检出库,然后运行

composer install

编码风格

我们遵循PSR2标准,并对所有函数强制执行PHPDocs。要运行测试以检查编码风格违规

vendor/bin/phpcs -p --standard=psr2 src/

单元测试

我们使用PHPSpec进行单元测试。要运行单元测试

vendor/bin/phpspec run

贡献

请阅读CONTRIBUTING.md,了解我们的行为准则和向我们的提交拉取请求的流程。

版本控制

我们使用SemVer进行版本控制。有关可用的版本,请参阅此存储库的标签

作者

查看参与此项目的贡献者列表。

许可

本项目受MIT许可协议的许可 - 有关详细信息,请参阅LICENSE.md文件。