purplebooth/git-lint-validators

This package is abandoned and no longer maintained. The author suggests using the sebastianfeldmann/captainhook package instead.

Lint git commits

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

This package is abandoned and no longer maintained. The author suggests using the sebastianfeldmann/captainhook package instead.

Git Lint

Scrutinizer Code Quality Build Status Dependency Status Latest Stable Version License

This project is designed to ensure that the commits you're making to a repository follow the git coding style. This is simply the basic validators.

The standard that they test for is the one described by Chris Beams.

The validations it implements are:

  • Separate subject from body with a blank line
  • Limit the subject line to 50 characters (soft limit, hard limit at 69)
  • Capitalize the subject line
  • Do not end the subject line with a period
  • Wrap the body at 72 characters

Getting Started

Prerequisities

You'll need to install:

  • PHP (Minimum 7.0)

Installing

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

Usage

Tool

You can try out this library by using it as a git commit hook.

Git hook installation

Use the install-git-hook Composer script to install the hook. An existing hook is backed to .git/hooks/commit-msg.bak.

composer install-git-hook

It's fairly customisable too, here are some options:

$ 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.com/book/ch5-2.html#Commit-Guidelines
 * https://github.com/blog/926-shiny-new-commit-styles


Output While Running


$ 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 commit message template installation

Use the install-git-commit-message-template Composer script to install and configure a commit message template following the rules of Chris Beams. The commit message template is written to .git/.gitmessage and will than be used when issuing a git commit w/o the message option.

composer install-git-commit-message-template

Library

You can use the whole library

<?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

Alternatively you could use the validators alone

<?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

Please depend on the interfaces rather than the concrete implementations. Concrete implementations may change without causing a BC break, interfaces changing will cause major version increment, indicating a BC break.

Running the tests

First checkout the library, then run

composer install

Coding Style

We follow PSR2, and also enforce PHPDocs on all functions. To run the tests for coding style violations

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

Unit tests

We use PHPSpec for unit tests. To run the unit tests

vendor/bin/phpspec run

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.