|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App; |
|
4
|
|
|
|
|
5
|
|
|
use Interop\Container\ContainerInterface; |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class Handler |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
private $scripts; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var Executor |
|
18
|
|
|
*/ |
|
19
|
|
|
private $executor; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
4 |
|
public function __construct(ContainerInterface $ci, Executor $executor) |
|
23
|
|
|
{ |
|
24
|
4 |
|
$this->executor = $executor; |
|
25
|
4 |
|
$this->scripts = $ci->get('scripts'); |
|
|
|
|
|
|
26
|
4 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
1 |
|
public function handleDeploy(array $event, array $build) |
|
30
|
|
|
{ |
|
31
|
1 |
|
if ($build['status'] === 'created') { |
|
32
|
1 |
|
$projectName = $event['project']['path_with_namespace']; |
|
33
|
1 |
|
$buildId = $build['id']; |
|
34
|
1 |
|
$commitId = $event['commit']['id']; |
|
35
|
1 |
|
$name = $build['name']; |
|
36
|
1 |
|
if (isset($this->scripts[$projectName]['deploy'][$name])) { |
|
37
|
1 |
|
$this->executeCommand($this->scripts[$projectName]['deploy'][$name], [ |
|
38
|
1 |
|
'HOOK_PROJECT_PATH' => $projectName, |
|
39
|
1 |
|
'HOOK_ENV_NAME' => $name, |
|
40
|
1 |
|
'HOOK_BUILD_ID' => $buildId, |
|
41
|
|
|
'HOOK_BUILD_REF' => $commitId |
|
42
|
1 |
|
]); |
|
43
|
1 |
|
} |
|
44
|
1 |
|
} |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
1 |
View Code Duplication |
public function handlePush(array $event) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
1 |
|
$projectName = $event['project']['path_with_namespace']; |
|
51
|
1 |
|
$ref = $event['ref']; |
|
52
|
1 |
|
if (isset($this->scripts[$projectName]['push'][$ref])) { |
|
53
|
1 |
|
$this->executeCommand($this->scripts[$projectName]['push'][$ref], [ |
|
54
|
1 |
|
'HOOK_PROJECT_PATH' => $projectName, |
|
55
|
1 |
|
'HOOK_REF' => $ref, |
|
56
|
1 |
|
'HOOK_BRANCH'=> $this->extractBranchName($ref), |
|
57
|
1 |
|
'HOOK_BUILD_REF' => $event['after'] |
|
58
|
1 |
|
]); |
|
59
|
1 |
|
} |
|
60
|
1 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
1 |
View Code Duplication |
public function handleTag(array $event) |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
1 |
|
$projectName = $event['project']['path_with_namespace']; |
|
66
|
1 |
|
$ref = $event['ref']; |
|
67
|
1 |
|
if (isset($this->scripts[$projectName]['tag'])) { |
|
68
|
1 |
|
$this->executeCommand($this->scripts[$projectName]['tag'], [ |
|
69
|
1 |
|
'HOOK_PROJECT_PATH' => $projectName, |
|
70
|
1 |
|
'HOOK_REF' => $ref, |
|
71
|
1 |
|
'HOOK_TAG'=> $this->extractTagName($ref), |
|
72
|
1 |
|
'HOOK_BUILD_REF' => $event['after'] |
|
73
|
1 |
|
]); |
|
74
|
1 |
|
} |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
1 |
|
private function extractBranchName($ref) |
|
79
|
|
|
{ |
|
80
|
1 |
|
return substr($ref, strlen('refs/heads/')); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
1 |
|
private function extractTagName($ref) |
|
85
|
|
|
{ |
|
86
|
1 |
|
return substr($ref, strlen('refs/tags/')); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string|array $scriptPath |
|
92
|
|
|
* @param array $env |
|
93
|
|
|
*/ |
|
94
|
3 |
|
private function executeCommand($scriptPath, array $env) |
|
95
|
|
|
{ |
|
96
|
3 |
|
$this->executor->executeCommand($scriptPath, $env); |
|
97
|
3 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..