Actions & Conditions

Here's a list of all CaptainHook's built-in Actions and Conditions.

Actions

Commit-Message validation

Enforce Chris Beams commit message rules

Make sure your you commit message complies to the following rules.

{
  "action": "\CaptainHook\App\Hook\Message\Action\Beams",
  "options": []
}

Commit message regex validation

Use a regex to validate your commit messages.

{
  "action": "\CaptainHook\App\Hook\Message\Action\Regex",
  "options": {
    "regex": "#.*#i",
    "error": "No match for: %s",
    "success": "Found match: %s"
  }
}
Options "error" and "success" are optional.

Define rules for your commit messages

Use CaptainHooks built in rules, or write your own ones.

{
  "action": "\CaptainHook\App\Hook\Message\Action\Rules",
  "options": [
    "\CaptainHook\App\Hook\Message\Rule\MsgNotEmpty"
  ]
}

Pre-Commit / Pre-Push

Composer lock file check

Make sure your composer.lock file ist up to date.

{
  "action": "\CaptainHook\App\Hook\Composer\Action\CheckLockFile",
  "options": []
}

Lint all changed PHP files

Make sure your PHP code doesn't contain any syntax errors.

{
  "action": "\CaptainHook\App\Hook\PHP\Action\Linting",
  "options": []
}

Monitor your unit test code coverage

Make sure you code coverage doesn't decrease beyond a given percent value.

{
  "action": "\CaptainHook\App\Hook\PHP\Action\TestCoverage",
  "options": {
    "minCoverage": 90,
    "cloverXml": "build/logs/clover.xml"
  }
}

Check if files are too big

Make sure you do not commit files that are bigger then a configured size limit.
Use 'B', 'K' or 'M' as size indication.

{
  "action": "\CaptainHook\App\Hook\File\Action\MaxSize",
  "options": {
    "maxSize": "5M"
  }
}

Check if a file is empty or does not exist

Make sure you do not commit if there is any file of a configured list that is not empty. The following configuration makes sure you will not commit log files with contents to the repository.

{
  "action": "\CaptainHook\App\Hook\File\Action\IsEmpty",
  "options": {
    "files": [
      ".env",
      "logs/event.log",
      "logs/app/*.log"
    ]
  }
}

Check if a file is not empty

Make sure you do not commit empty files to the repository. With this configuration you can make sure that README files are not commited without any contents.

{
  "action": "\CaptainHook\App\Hook\File\Action\IsNotEmpty",
  "options": {
    "files": [
      "README.md",
      "src/Modules/**/README.md"
    ]
  }
}

Check if a file does not contain certain text

Make sure you do not commit specific contents to a list of file types.

{
  "action": "\CaptainHook\App\Hook\File\Action\DoesNotContain",
  "options": {
    "regex": "#print_r|var_dump#i"
    "regexName": "debug output"
    "fileExtensions": [
      "inc",
      "php"
    ]
  }
}

Ensure a file exists

Make sure you are only allowed to push if configured files exist in the repository.

{
  "action": "\CaptainHook\App\Hook\File\Action\Exists",
  "options": {
    "files": [
      "tests/**/*Tests.php",
      "README.md"
    ]
  }
}

Enforce branch naming rules

Make sure branch names match a configured regex.

{
  "action": "\CaptainHook\App\Hook\Branch\Action\EnsureNaming",
  "options": {
    "regex": "#master|integration|feature/[a-z]+-[0-9]+#"
  }
}

Post-Merge, Post-Rewrite, Post-Checkout

Display notifications if you merge or checkout commits with notifications

Trigger notifications with git commit messages. Use git-notify: in your commit message to display notifications after merge, rebase or checkout.
Inspired by: git-notify from Jani Eväkallio

Update dev tooling

git-notify: WARNING
Please update your dev tooling

{
  "action": "\CaptainHook\App\Hook\Notify\Action\Notify",
  "options": {
    "prefix": "git-notify:"
  }
}

Conditions

All files changed

Execute an action only if all of the configured files changed.

{
    "action": "my-action",
    "options": [],
    "conditions": [
        {
            "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileChanged\\All",
            "args": [
                [
                    "trigger-file-1",
                    "trigger-file-2"
                ]
            ]
        }
    ]
}

Any file changed

Execute an action only if any of the configured files changed.

{
    "action": "composer install",
    "options": [],
    "conditions": [
        {
            "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileChanged\\Any",
            "args": [
                [
                    "composer.json",
                    "composer.lock"
                ]
            ]
        }
    ]
}