Skip to content

Commit 2df2854

Browse files
Merge pull request #277 from feature/config-shorthands
Add action and condition shorthands to simplify the configuration
2 parents dfc89b3 + e361556 commit 2df2854

File tree

26 files changed

+535
-97
lines changed

26 files changed

+535
-97
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "library",
44
"description": "PHP git hook manager",
55
"keywords": ["git", "hooks", "pre-commit", "pre-push", "commit-msg", "prepare-commit-msg", "post-merge"],
6-
"homepage": "http://php.captainhook.info/",
6+
"homepage": "https://php.captainhook.info/",
77
"license": "MIT",
88
"authors": [
99
{

src/Hook/Branch/Action/BlockFixupAndSquashCommits.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
* This action blocks pushes that contain fixup! or squash! commits.
2828
* Just as a security layer, so you are not pushing stuff you wanted to autosquash.
2929
*
30-
* Configure like this:
31-
*
30+
* Example configuration:
31+
* <code>
3232
* {
33-
* "action": "\\CaptainHook\\App\\Hook\\Branch\\Action\\BlockFixupAndSquashCommits",
34-
* "options": {
35-
* "blockSquashCommits": true,
36-
* "blockFixupCommits": true,
37-
* "protectedBranches": ["main", "master", "integration"]
38-
* },
39-
* "conditions": []
40-
* }
33+
* "action": "CaptainHook.Branch.PreventPushOfFixupAndSquashCommits",
34+
* "options": {
35+
* "blockSquashCommits": true,
36+
* "blockFixupCommits": true,
37+
* "protectedBranches": ["main", "master", "integration"]
38+
* }
39+
* }
40+
* </code>
4141
*
4242
* @package CaptainHook
4343
* @author Sebastian Feldmann <[email protected]>

src/Hook/Branch/Action/EnsureNaming.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
/**
2323
* Class EnsureNaming
2424
*
25+
* This Action makes sure you are on a branch that follows your naming conventions.
26+
*
27+
* Example configuration:
28+
* <code>
29+
* {
30+
* "action": "CaptainHook.Branch.EnsureNaming",
31+
* "options": {
32+
* "regex": "#feature/issue[0-9]+-.*#i",
33+
* "error": "Arr matey! Ye be on the wrong branch!",
34+
* "success": "All clear, Captain! Full speed ahead!",
35+
* }
36+
* }
37+
* </code>
38+
*
2539
* @package CaptainHook
2640
* @author Felix Edelmann <[email protected]>
2741
* @link https://github.com/captainhook-git/captainhook

src/Hook/Condition/Branch/NotOn.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@
1818
use SebastianFeldmann\Git\Repository;
1919

2020
/**
21-
* NotOn condition
21+
* NotOn Branch condition
22+
*
23+
* Example configuration:
24+
* <code>
25+
* {
26+
* "action": "some-action",
27+
* "conditions": [
28+
* {
29+
* "exec": "CaptainHook.Status.NotOnBranch",
30+
* "args": ["not-on-this-branch"]
31+
* }
32+
* ]
33+
* }
34+
* </code>
2235
*
2336
* @package CaptainHook
2437
* @author Sebastian Feldmann <[email protected]>

src/Hook/Condition/Branch/NotOnMatching.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@
1818
use SebastianFeldmann\Git\Repository;
1919

2020
/**
21-
* NotOnMatching condition
21+
* NotOnMatching Branch condition
22+
*
23+
* Example configuration:
24+
* <code>
25+
* {
26+
* "action": "some-action",
27+
* "conditions": [
28+
* {
29+
* "exec": "CaptainHook.Status.NotOnMatchingBranch",
30+
* "args": ["#^branches-names/not-matching[0-9]+-this-regex$#i"]
31+
* }
32+
* ]
33+
* }
34+
* </code>
2235
*
2336
* @package CaptainHook
2437
* @author Sebastian Feldmann <[email protected]>

src/Hook/Condition/Branch/On.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@
1818
use SebastianFeldmann\Git\Repository;
1919

2020
/**
21-
* On condition
21+
* On Branch condition
22+
*
23+
* Example configuration:
24+
* <code>
25+
* {
26+
* "action": "some-action",
27+
* "conditions": [
28+
* {
29+
* "exec": "CaptainHook.Status.OnBranch",
30+
* "args": ["only-on-this-branch"]
31+
* }
32+
* ]
33+
* }
34+
* </code>
2235
*
2336
* @package CaptainHook
2437
* @author Sebastian Feldmann <[email protected]>

src/Hook/Condition/Branch/OnMatching.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@
1818
use SebastianFeldmann\Git\Repository;
1919

2020
/**
21-
* OnMatching condition
21+
* OnMatching Branch condition
22+
*
23+
* Example configuration:
24+
* <code>
25+
* {
26+
* "action": "some-action",
27+
* "conditions": [
28+
* {
29+
* "exec": "CaptainHook.Status.OnMatchingBranch",
30+
* "args": ["#^branches-names/matching[0-9]+-this-regex$#i"]
31+
* }
32+
* ]
33+
* }
34+
* </code>
2235
*
2336
* @package CaptainHook
2437
* @author Sebastian Feldmann <[email protected]>

src/Hook/Condition/Config/CustomValueIsFalsy.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
use SebastianFeldmann\Git\Repository;
1818

1919
/**
20-
* Class CustomValueIsFalsy
20+
* Condition CustomValueIsFalsy
21+
*
22+
* With this condition, you can check if a given custom value is falsy.
23+
* The Action only is executed if the custom value is falsy.
24+
* Values considered falsy are, 0, null, empty string, empty array and false.
2125
*
2226
* Example configuration:
2327
*
24-
* "action": "some-action"
25-
* "conditions": [
26-
* {"exec": "\\CaptainHook\\App\\Hook\\Condition\\Config\\CustomValueIsFalsy",
27-
* "args": [
28-
* "NAME_OF_CUSTOM_VALUE"
29-
* ]}
30-
* ]
28+
* <code>
29+
* {
30+
* "action": "some-action"
31+
* "conditions": [
32+
* {
33+
* "exec": "CaptainHook.Config.CustomValueIsFalsy",
34+
* "args": ["NAME_OF_CUSTOM_VALUE"]
35+
* }
36+
* ]
37+
* }
38+
* </code>
3139
*
3240
* @package CaptainHook
3341
* @author Sebastian Feldmann <[email protected]>
3442
* @link https://github.com/captainhook-git/captainhook
3543
* @since Class available since Release 5.17.2
44+
* @short CaptainHook.Config.CustomValueIsFalsy
3645
*/
3746
class CustomValueIsFalsy extends Condition\Config
3847
{

src/Hook/Condition/Config/CustomValueIsTruthy.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
*
2222
* Example configuration:
2323
*
24-
* "action": "some-action"
25-
* "conditions": [
26-
* {"exec": "\\CaptainHook\\App\\Hook\\Condition\\Config\\CustomValueIsTruthy",
27-
* "args": [
28-
* "NAME_OF_CUSTOM_VALUE"
29-
* ]}
30-
* ]
24+
* <code>
25+
* {
26+
* "action": "some-action"
27+
* "conditions": [
28+
* {
29+
* "exec": "CaptainHook.Config.CustomValueIsTruthy",
30+
* "args": ["NAME_OF_CUSTOM_VALUE"]
31+
* }
32+
* ]
33+
* }
34+
* </code>
3135
*
3236
* @package CaptainHook
3337
* @author Sebastian Feldmann <[email protected]>

src/Hook/Condition/FileChanged/All.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
* The FileChange condition is applicable for `post-merge` and `post-checkout` hooks.
2222
* It checks if all configured files are updated within the last change set.
2323
*
24+
* Example configuration:
25+
*
26+
* <code>
27+
* {
28+
* "action": "some-action"
29+
* "conditions": [
30+
* {
31+
* "exec": "CaptainHook.FileChanged.All",
32+
* "args": [
33+
* ["list", "of", "files"]
34+
* ]
35+
* }
36+
* ]
37+
* }
38+
* </code>
39+
*
2440
* @package CaptainHook
2541
* @author Sebastian Feldmann <[email protected]>
2642
* @link https://github.com/captainhook-git/captainhook

0 commit comments

Comments
 (0)