purplebooth/git-github-lint

Lint github commits and update their status

v1.0.0 2016-08-07 18:56 UTC

README

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 the library component with no web frontend.

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 PurpleBooth/git-github-lint

Usage

Tool

You can try out this library by using it as a tool. You'll need to generate a token on the GitHub Personal Access Token Page.

Usage


Billies-MacBook-Pro-2:git-github-lint billie$ bin/git-github-lint help git-github-lint:pr
Usage:
  git-github-lint:pr [options] [--] <github-username> <github-repository> <pull-request-id>

Arguments:
  github-username       GitHub Username
  github-repository     GitHub Repository
  pull-request-id       The ID of the pull request

Options:
  -t, --token=TOKEN     The token to authenticate to the API with.
  -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:
 Evaluates a the commits in a pull request and checks that their messages match the style advised by Git. It will then update the "status" in github (that little dot next to the commits).


 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

$ php vendor/bin/git-github-lint git-github-lint:pr \
                                 -t my-token \
                                 PurpleBooth \
                                 git-github-lint \
                                 3

git-github-lint:pr
==================

 // Analysing PR PurpleBooth/git-github-lint#3


 [OK] Finished!

You can look at the pull requests on this repo to see what the effect is like in person.

Library

You can use the whole library

<?php

$gitHubClient = new \Github\Client()

/** @var GitHubLint $gitHubLint **/
$gitHubLint = new GitHubLintImplementation($gitHubClient);
$gitHubLint->analyse('PurpleBooth', 'git-github-lint', 3);
// -> The commits on your PR should now be updated with a status

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

To run the tests for coding style

First checkout the library, then run

composer install

Coding Style

We follow PSR2, and also enforce PHPDocs on all functions

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

Unit tests

We use PHPSpec for 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