Conditions
Here's a list of all built-in conditions:
Logic conditions | |
---|---|
CaptainHook::Logic.And | Combine multiple conditions by AND |
CaptainHook::Logic.Or | Combine multiple conditions by OR |
All hooks | |
CaptainHook::Status.OnBranch | Check if we are on a particular branch |
CaptainHook::Config.CustomValueIsTruthy | Check if a custom config is true, 1, yes or on |
CaptainHook::Config.CustomValueIsFalsy | Check if a custom config is false, 0, no or off |
pre-commit | |
CaptainHook::FileStaged.All | Check if all of the configured files are staged for commit |
CaptainHook::FileStaged.Any | Check if any of the configured files is staged for commit |
CaptainHook::FileStaged.ThatIs | Check if a file of a given type, or in a given directory is staged for commit |
post-checkout / post-merge / post-rewrite / pre-push | |
CaptainHook::FileChange.All | Check if all of the configured files are changed |
CaptainHook::FileChange.Any | Check if any of the configured files is changed |
CaptainHook::FileChange.ThatIs | Check if a file was changed that is of a given type or in a given directory |
You can build your own conditions. Just use a simple script or binary which must return an exit code. The exit code 0 means the condition applies; any exit code other than 0 means the condition does not apply.
Custom
all hooks
{
"conditions": [
{
"run": "my-script.sh --option my-arg"
}
]
}
Logic AND
all hooks
This Condition can have a list of sub Conditions. Only if all the sub conditions are true the logic condition is true as well.
{
"conditions": [
{
"run": "CaptainHook::Logic.And",
"conditions": [
{
"run": "CaptainHook::Status.OnBranch",
"options": {
"branch": "master"
}
},
...
]
}
]
}
Logic OR
all hooks
This Condition can have a list of sub Conditions. If any of the sub conditions is true the logic condition is true as well.
{
"conditions": [
{
"run": "CaptainHook::Logic.Or",
"conditions": [
{
"run": "CaptainHook::Status.OnBranch",
"options": {
"branch": "master"
}
},
...
]
}
]
}
OnBranch
all hooks
This Condition expects just one argument, the name of the branch.
{
"conditions": [
{
"run": "CaptainHook::Status.OnBranch",
"options": {
"branch": "master"
}
}
]
}
CustomValueIsTruthy
all hooks
This Condition expects just one argument, the name of the custom config value to check.
{
"conditions": [
{
"run": "CaptainHook::Config.CustomConfigValueIsTruthy",
"options": {
"value": "MY_CONFIG_VALUE"
}
}
]
}
CustomValueIsFalsy
all hooks
This Condition expects just one argument, the name of the custom config value to check.
{
"conditions": [
{
"run": "CaptainHook::Config.CustomConfigValueIsFalsy",
"options": {
"value": "MY_CONFIG_VALUE"
}
}
]
}
FileStaged.All
pre-commit
Expecting a list of file names or pattern.
{
"conditions": [
{
"run": "CaptainHook::FileStaged.All",
"options": {
"files": ["foo.html", "bar.html", "*.css"]
}
}
]
}
FileStaged.Any
pre-commit
Expecting a list of file names or pattern.
{
"conditions": [
{
"run": "CaptainHook::FileStaged.Any",
"options": {
"files": ["foo.html", "bar.html", "*.css"]
}
}
]
}
FileStaged.ThatIs
pre-commit
Expecting just the type of file you want to watch as string.
{
"conditions": [
{
"run": "CaptainHook::FileStaged.OfType",
"options": {
"of-type": "go",
"in-directory": "cmd"
}
}
]
}
FileChanged.All
post-checkout post-merge
Expecting a list of file names or pattern.
{
"conditions": [
{
"run": "CaptainHook::FileChanged.All",
"options": {
"files": ["foo.html", "bar.html", "*.php"]
}
}
]
}
FileChanged.Any
post-checkout post-merge
Expecting a list of file names or pattern.
{
"conditions": [
{
"run": "CaptainHook::FileChanged.Any‚",
"options": {
"files": ["foo.html", "bar.html", "*.css"]
}
}
]
}
FileChanged.ThatIs
pre-push
Expecting just the type of file you want to watch as string.
{
"conditions": [
{
"run": "CaptainHook::FileChange.OfType",
"options": {
"of-type": "go",
"in-directory": "cmd"
}
}
]
}