How to use the "Cli" condition in the hooks ? #176
-
|
Hi there ! how to use the Cli condition in the hooks? Any help is appreciated I have the following configuration: "commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Regex",
"options": {
"regex": "#^(TICKET)-[1-9][0-9]* #",
"error": "No match for: %s",
"success": "Found match: %s"
},
"conditions": [
{
"exec": "\\CaptainHook\\App\\Hook\\Condition\\Cli",
"args": [
"if [ \"$ENV_VARIABLE\"==\"1\" ]; then exit 1; else exit 0; fi;"
]
}
]
}but this fails with: PHP Fatal error: Uncaught TypeError: CaptainHook\App\Hook\Condition\Cli::__construct(): Argument #1 ($processor) must be of type SebastianFeldmann\Cli\Processor, string given, called in phar:///var/www/.tools/captainhook/src/Runner/Condition.php on line 98 and defined in phar:///var/www/.tools/captainhook/src/Hook/Condition/Cli.php:43
Stack trace:
#0 phar:///var/www/.tools/captainhook/src/Runner/Condition.php(98): CaptainHook\App\Hook\Condition\Cli->__construct('if [ "$ENV_VARIABLE...')
#1 phar:///var/www/.tools/captainhook/src/Runner/Condition.php(68): CaptainHook\App\Runner\Condition->createCondition(Object(CaptainHook\App\Config\Condition))
#2 phar:///var/www/.tools/captainhook/src/Runner/Hook.php(327): CaptainHook\App\Runner\Condition->doesConditionApply(Object(CaptainHook\App\Config\Condition))
#3 phar:///var/www/.tools/captainhook/src/Runner/Hook.php(259): CaptainHook\App\Runner\Hook->doConditionsApply(Array)
#4 phar:///var/www/.tools/captainhook/src/Runner/Hook.php(219): CaptainHook\App\Runner\Hook->handleAction(Object(CaptainHook\App\Config\Action))
#5 phar:///var/www/.tools/captainhook/src/Runner/Hook.php(204): CaptainHook\App\Runner\Hook->executeFailOnFirstError(Array)
#6 phar:///var/www/.tools/captainhook/src/Runner/Hook.php(119): CaptainHook\App\Runner\Hook->executeActions(Array)
#7 phar:///var/www/.tools/captainhook/src/Console/Command/Hook.php(71): CaptainHook\App\Runner\Hook->run()
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
To use a cli command for a condition all you have to do is to put the command in the |
Beta Was this translation helpful? Give feedback.
To use a cli command for a condition all you have to do is to put the command in the
execpart of the configuration.The Cap'n will automatically detect that it has to execute a CLI command and will setup the
Cliaction automatically, you don't have to do that manually.The only thing your command has to do is to exit with code
0if the condition should apply and anything else if the condition should not apply.