-
Notifications
You must be signed in to change notification settings - Fork 2
/
hook.php
47 lines (31 loc) · 1.14 KB
/
hook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
require_once 'vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
$logger = new Katzgrau\KLogger\Logger(__DIR__.'/logs');
// load and parse hook config file
$config_file_path = __DIR__. '/_config.yml';
$config = Yaml::parse($config_file_path);
$logger->info("--------------- a new hook ----------------");
// read gitlab post body
$body = file_get_contents('php://input');
$logger->debug("hook body:\n". $body);
// parse gitlab payload
$payload = json_decode($body,true);
$logger->debug('hook payload', $payload);
// get project name
$project = $_REQUEST['p'];
$logger->debug("hook project: " .$project);
// get project config
$project_config = $config[$project];
if ($project_config)
{
$logger->debug("hook config for '" . $project . "'", $project_config);
$hookClass = $project_config['hook-class'];
require_once 'hooks/class.' . $hookClass . '.php';
$hook = new $hookClass($project, $project_config, $payload);
$hook->run();
}
else
{
$logger->debug("hook config for '". $project . "' not found");
}