1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of CaptainHook |
5
|
|
|
* |
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace CaptainHook\App; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Hooks |
18
|
|
|
* |
19
|
|
|
* Defines the list of hooks that can be handled with captainhook and provides some name constants. |
20
|
|
|
* |
21
|
|
|
* @package CaptainHook |
22
|
|
|
* @author Andrea Heigl <[email protected]> |
23
|
|
|
* @link https://github.com/captainhookphp/captainhook |
24
|
|
|
* @since Class available since Release 3.0.1 |
25
|
|
|
*/ |
26
|
|
|
final class Hooks |
27
|
|
|
{ |
28
|
|
|
public const PRE_COMMIT = 'pre-commit'; |
29
|
|
|
|
30
|
|
|
public const PRE_PUSH = 'pre-push'; |
31
|
|
|
|
32
|
|
|
public const COMMIT_MSG = 'commit-msg'; |
33
|
|
|
|
34
|
|
|
public const PREPARE_COMMIT_MSG = 'prepare-commit-msg'; |
35
|
|
|
|
36
|
|
|
public const POST_COMMIT = 'post-commit'; |
37
|
|
|
|
38
|
|
|
public const POST_MERGE = 'post-merge'; |
39
|
|
|
|
40
|
|
|
public const POST_CHECKOUT = 'post-checkout'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
97 |
|
* Returns the list of valid hooks |
44
|
|
|
* |
45
|
|
|
* @return array<string> |
46
|
97 |
|
*/ |
47
|
97 |
|
public static function getValidHooks(): array |
48
|
97 |
|
{ |
49
|
97 |
|
return [ |
50
|
97 |
|
self::COMMIT_MSG => 'CommitMsg', |
51
|
97 |
|
self::PRE_PUSH => 'PrePush', |
52
|
97 |
|
self::PRE_COMMIT => 'PreCommit', |
53
|
|
|
self::PREPARE_COMMIT_MSG => 'PrepareCommitMsg', |
54
|
|
|
self::POST_COMMIT => 'PostCommit', |
55
|
|
|
self::POST_MERGE => 'PostMerge', |
56
|
|
|
self::POST_CHECKOUT => 'PostCheckout', |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the argument placeholders for a given hook |
62
|
|
|
* |
63
|
|
|
* @param string $hook |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public static function getOriginalHookArguments(string $hook): string |
67
|
|
|
{ |
68
|
|
|
static $arguments = [ |
69
|
|
|
Hooks::COMMIT_MSG => ' {$FILE}', |
70
|
|
|
Hooks::POST_MERGE => ' {$SQUASH}', |
71
|
|
|
Hooks::PRE_COMMIT => '', |
72
|
|
|
Hooks::PRE_PUSH => ' {$TARGET} {$URL}', |
73
|
|
|
Hooks::PREPARE_COMMIT_MSG => ' {$FILE} {$MODE} {$HASH}', |
74
|
|
|
Hooks::POST_CHECKOUT => ' {$PREVIOUSHEAD} {$NEWHEAD} {$MODE}', |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
return $arguments[$hook]; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|