All Projects → sjparkinson → Static Review

sjparkinson / Static Review

Licence: mit
✋ An extendible framework for version control hooks.

Projects that are alternatives of or similar to Static Review

reviewio
code review stats for
Stars: ✭ 22 (-93.33%)
Mutual labels:  code-review, command-line-tool
Composer Git Hooks
Easily manage git hooks in your composer config
Stars: ✭ 838 (+153.94%)
Mutual labels:  command-line-tool, git-hooks
Quickfix
The best stupid idea for fixing problems in node modules.
Stars: ✭ 267 (-19.09%)
Mutual labels:  command-line-tool
Git Duet
Support for pairing with git
Stars: ✭ 313 (-5.15%)
Mutual labels:  command-line-tool
Circleci Cli
Use CircleCI from the command line
Stars: ✭ 297 (-10%)
Mutual labels:  command-line-tool
Php Malware Scanner
Scans PHP files for malwares and known threats
Stars: ✭ 274 (-16.97%)
Mutual labels:  command-line-tool
Reviewdog
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language
Stars: ✭ 4,541 (+1276.06%)
Mutual labels:  code-review
Dockly
Immersive terminal interface for managing docker containers and services
Stars: ✭ 3,034 (+819.39%)
Mutual labels:  command-line-tool
Molotov
Load Testing Tool
Stars: ✭ 318 (-3.64%)
Mutual labels:  command-line-tool
Whatsapp Play
Command line software through which you can play with your WhatsApp. It is having different options to play with your WhatsApp like message blast, online tracking, whatsapp chat..
Stars: ✭ 289 (-12.42%)
Mutual labels:  command-line-tool
Laravel Packer
Awesome Command Line Tool for speeding up your package creation.
Stars: ✭ 313 (-5.15%)
Mutual labels:  command-line-tool
Theme.sh
A script which lets you set your $terminal theme.
Stars: ✭ 290 (-12.12%)
Mutual labels:  command-line-tool
Shiba
Catch bad SQL queries before they cause problems in production
Stars: ✭ 277 (-16.06%)
Mutual labels:  code-review
Commandtrayhost
A command line program monitor systray for Windows
Stars: ✭ 303 (-8.18%)
Mutual labels:  command-line-tool
Starcli
✨ Browse GitHub trending projects from your command line
Stars: ✭ 269 (-18.48%)
Mutual labels:  command-line-tool
Raptor
Web-based Source Code Vulnerability Scanner
Stars: ✭ 314 (-4.85%)
Mutual labels:  code-review
Github cli
GitHub on your command line. Use your terminal, not the browser.
Stars: ✭ 263 (-20.3%)
Mutual labels:  command-line-tool
Sourcedocs
Generate Markdown documentation from source code
Stars: ✭ 286 (-13.33%)
Mutual labels:  command-line-tool
Define
A command-line dictionary (thesaurus) app, with access to multiple sources, written in Go.
Stars: ✭ 298 (-9.7%)
Mutual labels:  command-line-tool
Cpp Project
Boiler plate template for C++ projects, with CMake, Doctest, Travis CI, Appveyor, Github Actions and coverage reports.
Stars: ✭ 328 (-0.61%)
Mutual labels:  code-review

static-review

This package is abandoned 🚨.

See GrumPHP for a maintained alternative.


An extendable framework for version control hooks.

StaticReview Success Demo

Usage

For a composer managed project you can simply run the following ...

$ composer require sjparkinson/static-review

Hooks can then be installed like so ...

$ vendor/bin/static-review.php hook:install vendor/sjparkinson/static-review/hooks/example-pre-commit.php .git/hooks/pre-commit

Otherwise, if you don't use composer ...

$ git clone https://github.com/sjparkinson/static-review.git
$ cd static-review/
$ composer install --no-dev --optimize-autoloader
$ bin/static-review.php hook:install hooks/example-pre-commit.php ~/.../.git/hooks/pre-commit

Global Installation and Usage

The hooks can also be used for any project if you install static-review globally:

$ composer g require sjparkinson/static-review

Then, just install the hooks as you would normally but reference the global installation path:

$ static-review.php hook:install ~/.composer/vendor/sjparkinson/static-review/hooks/static-review-commit-msg.php .git/hooks/commit-msg

This assumes you have set up global composer paths.

Example Hooks

Static Review can be used for both files and commit message review. Below are basic hooks for each.

For Files

#!/usr/bin/env php
<?php

include __DIR__ . '/../../../autoload.php';

// Reference the required classes.
use StaticReview\StaticReview;
use StaticReview\Review\General\LineEndingsReview;
[...]

$reporter = new Reporter();
$review   = new StaticReview($reporter);

// Add any reviews to the StaticReview instance, supports a fluent interface.
$review->addReview(new LineEndingsReview());

$git = new GitVersionControl();

// Review the staged files.
$review->files($git->getStagedFiles());

// Check if any issues were found.
// Exit with a non-zero status to block the commit.
($reporter->hasIssues()) ? exit(1) : exit(0);

For Commit Messages

#!/usr/bin/env php
<?php

include __DIR__ . '/../../../autoload.php';

// Reference the required classes.
use StaticReview\StaticReview;
use StaticReview\Review\Message\BodyLineLengthReview;
[...]

$reporter = new Reporter();
$review   = new StaticReview($reporter);

// Add any reviews to the StaticReview instance, supports a fluent interface.
$review->addReview(new BodyLineLengthReview());

$git = new GitVersionControl();

// Review the current commit message.
// The hook is passed the file holding the commit message as the first argument.
$review->message($git->getCommitMessage($argv[1]));

// Check if any issues were found.
// Exit with a non-zero status to block the commit.
($reporter->hasIssues()) ? exit(1) : exit(0);

Example Review For Files

class NoCommitTagReview extends AbstractFileReview
{
    // Review any text based file.
    public function canReviewFile(FileInterface $file)
    {
        $mime = $file->getMimeType();

        // check to see if the mime-type starts with 'text'
        return (substr($mime, 0, 4) === 'text');
    }

    // Checks if the file contains `NOCOMMIT`.
    public function review(ReporterInterface $reporter, ReviewableInterface $file)
    {
        $cmd = sprintf('grep --fixed-strings --ignore-case --quiet "NOCOMMIT" %s', $file->getFullPath());

        $process = $this->getProcess($cmd);
        $process->run();

        if ($process->isSuccessful()) {
            $message = 'A NOCOMMIT tag was found';
            $reporter->error($message, $this, $file);
        }
    }
}

Example Review For Messages

class WorkInProgressReview extends AbstractMessageReview
{
    // Check if the commit message contains "wip"
    public function review(ReporterInterface $reporter, ReviewableInterface $commit)
    {
        $fulltext = $commit->getSubject() . PHP_EOL . $commit->getBody();

        if (preg_match('/\bwip\b/i', $fulltext)) {
            $message = 'Do not commit WIP to shared branches';
            $reporter->error($message, $this, $commit);
        }
    }
}

Unit Tests

See vagrantup.com and phpunit.de.

$ git clone https://github.com/sjparkinson/static-review.git
$ cd static-review/
$ vagrant up
$ vagrant ssh
...
$ cd /srv
$ composer update
$ composer test

Licence

The content of this library is released under the MIT License by Samuel Parkinson.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].