sashas777/captainhook

PHP git hook manager

Fund package maintenance!
sashas777

4.5.1.2 2019-08-16 18:04 UTC

README

Latest Stable Version Minimum PHP Version Downloads License Build Status Scrutinizer Code Quality Code Coverage

CaptainHook

68747470733a2f2f6361707461696e686f6f6b7068702e6769746875622e696f2f6361707461696e686f6f6b2f6766782f63682e706e67

CaptainHook is an easy to use and very flexible git hook library for php developers. It enables you to configure your git hook actions in a simple json file.

You can use CaptainHook to validate or prepare your commit messages, ensure code quality or run unit tests before you commit or push changes to git. You can automatically clear local caches or install the latest composer dependencies after pulling the latest changes.

CaptainHook makes it easy to share hooks within your team and even can make sure that everybody in your team activates the hooks locally.

You can run cli commands, use some built in validators, or write your own PHP classes that get executed by CaptainHook. For more information have a look at the documentation.

Installation

Use Composer to install CaptainHook.

    $ composer require --dev captainhook/captainhook

If you want to make sure your whole team uses the same hooks and you want Composer to take care of the hook installation and activation you should use the CaptainHook composer-plugin instead.

    $ composer require --dev captainhook/plugin-composer

The plugin will make sure that the hooks get activated after every composer install or update.

Setup

After installing CaptainHook you can use the captainhook executable to create a configuration.

    $ vendor/bin/captainhook configure

Now there should be a captainhook.json configuration file.

If you are not using the composer-plugin you have to activate the hooks manually by installing them to your local .git repository. To do so just run the following captainhook command.

    $ vendor/bin/captainhook install

Have a look at this short installation video.

Install demo

Configuration

Here's an example captainhook.json configuration file.

{
  "commit-msg": {
    "enabled": true,
    "actions": [
      {
        "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Beams",
        "options": []
      }
    ]
  },
  "pre-commit": {
    "enabled": true,
    "actions": [
      {
        "action": "phpunit"
      },
      {
        "action": "phpcs --standard=psr2 src"
      }
    ]
  },
  "pre-push": {
    "enabled": false,
    "actions": []
  }
}