Code Monkey home page Code Monkey logo

githooks's Introduction

PHP Versions Supported

1. Wtyd/GitHooks

Are many other tools and composer plugins for manage git hooks. But GitHooks offers:

  • Standalone app. GitHooks is a binary (.phar) so its dependencies don't interfere with your application's dependencies.
  • Is managed with Composer. You don't need other tools like Phive or others.
  • Crentralizes all QA tools configuration (all of supported tools at least).
  • It abstracts developers away from how QA tools have to be executed by using only the githooks tool name-of-the-tool command.
  • You can also create your own scripts and configure any git hook.

Further, it can be used together with javascript validation tools like typicode/husky if you have hybrid projects.

2. Requirements

  • PHP >= 7.1
  • The tools you need to check the code.
  • Or your owns scripts for the hooks.

3. Install

1. GitHooks must be installed like dev requirement with composer:

composer require --dev wtyd/githooks

Note: for php < 8.1 you must add the next post-update-cmd event to the scripts section in your composer.json:

"scripts": {
    "post-update-cmd": [
      "Wtyd\\GitHooks\\Utils\\ComposerUpdater::phpOldVersions"
    ]
}

Then run composer update wtyd/githooks.

Until version 2.3.0 the method used was php72orMinorUpdate but it has been deprecated and will be removed from version 3.0.0

It is also convenient to add it to the post-install-cm event so that the rest of the project developers do not have problems with the build

"scripts": {
    "post-update-cmd": "Wtyd\\GitHooks\\Utils\\ComposerUpdater::phpOldVersions",
    "post-install-cmd": "Wtyd\\GitHooks\\Utils\\ComposerUpdater::phpOldVersions"
}

2. Install all needed supported tools. How you install the tools doesn't matter.

3. Initialize GitHooks with githooks conf:init. This command creates the configuration file in the root path (githooks.yml).

4. Run githooks hook. It Copies the script for launch GitHooks on the pre-commit event in .git/hooks directory. You can, also run githooks hook otherHook MyScriptFile.php for set any hook with a custom script. See the wiki for more information.

To ensure that it is configured automatically, we can configure the command in the post-update-cmd and post-install-cmd events of the composer.json file (scripts section):

"scripts": {
    "post-update-cmd": [
    "vendor/bin/githooks hook" // or "vendor/bin/githooks hook pre-commit MyScriptFile.php"
    ],
    "post-install-cmd": [
    "vendor/bin/githooks hook"
    ]
}

4. Usage

When you commit, all the configured code check tools are automatically launched. If your code pass all checks, GitHooks allows you to commit. If not, you have to fix the code and try again:

Imagen todo OK

Imagen con KO

You can also run GitHooks whenever you want. All tools at same time or one by one:

githooks tool all # Run all tools
githooks tool phpcs # Run only phpcs

Imagen de una herramienta

5. Supported Tools

At this moment, the supported tools are:

But you can set your own script on any git hook.

6. Set the Configuration File

The githooks.yml file is splitted on three parts:

6.1. Options

6.1.1. Execution

The execution flag marks how GitHooks will run:

  • full (the default option): executes always all tools setted against all path setted for each tool. For example, you setted phpcs for run in src and app directories. The commit only contains modified files from database directory. Phpcs will check src and app directories even if no files in these directories have been modified.
  • fast: this option runs the tools only against files modified by commit.
    • This option only affects the following tools: phpcs, phpmd, phpstan, and parallel-lint. The rest of the tools will run as the full option.
    • WARNING!!! You must set the excludes of the tools either in githooks.yml or in the configuration file of eath tool since this option overwrites the key paths of the tools so that they are executed only against the modified files.

6.1.2. Processes

Run multiple tools in multiple processes at same time (tool all command). The default number of processes is 1.

6.2. Tools

It is an array with the name of the tools that GitHooks will run. The name of the tools is their executable. If you want all the tools to be executed, the Tools key will be as follows:

Tools:
    - phpstan
    - security-checker
    - parallel-lint
    - phpcs
    - phpcbf
    - phpmd
    - phpcpd

The order in which the tools are is the order in which they will be executed.

6.3. Setting Tools

In next step you must configure the tools with the same name as in the Tools key. For example, for set phpcs:

phpcs:
    executablePath: vendor/bin/phpcs
    paths: [src, tests]
    ignore: [vendor]
    standard: 'PSR12'

All the available options are in the wiki.

7. Contributing

Contributions from others would be very much appreciated! Send pull request/issue. Check all steps for do that at Wiki section for Contributing. Thanks!

8. License

The MIT License (MIT). Please see License File for more information.

githooks's People

Contributors

pablo-lilao avatar wtyd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.