-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.php
35 lines (30 loc) · 958 Bytes
/
run.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
<?php
/**
* this is the file that should be called by the bitbucket post-commit hook
* it expects a payload of json data
*/
require_once dirname(__FILE__) . '/bootstrap.php';
try {
// check if ip is whitelisted or we won't process request
if (!HttpUtils::ipIsInRange($_SERVER['REMOTE_ADDR'], $config['ip_whitelist'])) {
throw new Exception(sprintf('IP %s is not whitelisted', $_SERVER['REMOTE_ADDR']), 403);
}
$input = file_get_contents('php://input');
// parse incoming data
try {
$parser = new BitBucketPostParser();
$parser->parse($input);
}
// if we can't parse it, we'll send bad request to bitbucket
catch (Exception $e) {
throw new Exception($e->getMessage(), 400);
}
// import to active collab
$connector = new ActiveCollabConnector($config);
$connector->import($parser);
}
catch (Exception $e) {
error_log($e->getMessage());
$statusCode = $e->getCode() > 0 ? $e->getCode() : 500;
HttpUtils::sendHeader($statusCode);
}