Giter Site home page Giter Site logo

crook's Introduction

Build Status Maintainability Codacy Badge Codacy Badge

Crook

First of all, Crook is a work in progress.

If you are not familiar with git hooks, you may want to read Git Hooks documentation first.

Crook is the simplest way to define and manage your Git Hooks. Its aim is to allow scripts from your composer.json run when git hook actions are triggered.

Usage

The aim of this project is to be as simple as possible, thus, you won't have to write any PHP code, you just need to install any packages from packagist and then make them run for partucular git hooks. The process is explained in the following sections.

Installation

Just run

$ composer require felipebool/crook --dev

Init Crook

$ vendor/bin/crook init will create crook.json configuration file and theHook in the root of your project.

Add a new hook

$ vendor/bin/crook add hook-name action-name will create a symbolic link from .git/hooks/hook-name to theHook, enabling that hook.

Remove a hook

$ vendor/bin/crook remove hook-name will remove the symbolic link .git/hooks/hook-name, disabling that hook.

Add a action to composer.json

When you add a new action using add you need to add what is expected to run when that action is triggered inside you composer.json. To do that, you must create a new entry inside the section scripts and then define what must run there.

Crook configuration file

Crook uses a json configuration file just like composer, it is called crook.json. The configuration is made, basically, by writting as a key the git hook name and as value the respective script entry in composer.json. See the following example

{
  "pre-commit": "code-check",
  "composer": "/home/felipe/bin/composer"
}

Although you are able to edit crook.json by yourself, you should do it using $ vendor/bin/crook in order to create the symbolic links. Only the composer path must be set manually. The mechanism is explained in the next section.

The mechanism

Every time you run a vendor/bin/crook add hook-name action-name Crook creates a symbolic link from .git/hooks/hook-name to /your/project/hook/theHook, simple as that.

Now, when git trigger the action hook-name, it will follow the link to /your/project/hook/theHook and Crook will then look for a script named action-name inside your project's composer.json and will execute the commands defined there.

Adding code validation using phpcs before any commit

In order to check your code against PSR2, you must do this

Add the script action inside composer.json

"scripts": {
  "code-check": "phpcs --standard=PSR2 src/",
}

Initialize crook

$ vendor/bin/crook init

Bind code-check to pre-commit hook

$ vendor/bin/crook add pre-commit code-check

Next time you run $ git commit -m 'some message' crook will run the code defined inside code-check and will prevent code from being commited if the check fail.

crook's People

Contributors

felipebool avatar ginfarma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

crook's Issues

remove requirement for composer path configuration

instead of this commit: f0be111

The project should fall back to composer or composer.phar from PATH.

Its unnecessary extra step to use the project. besides having this configurable via crook.json makes it impossible to share crook.json with other developers, i.e commit the file to git repo.

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.