forked from lkwdwrd/git-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket.php
50 lines (48 loc) · 2.05 KB
/
bitbucket.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
44
45
46
47
48
49
50
<?php
// Make sure we have a payload, stop if we do not.
if( ! isset( $_POST['payload'] ) )
die( '<h1>No payload present</h1><p>A BitBucket POST payload is required to deploy from this script.</p>' );
/**
* Tell the script this is an active end point.
*/
define( 'ACTIVE_DEPLOY_ENDPOINT', true );
require_once 'deploy-config.php';
/**
* Deploys BitBucket git repos
*/
class BitBucket_Deploy extends Deploy {
/**
* Decodes and validates the data from bitbucket and calls the
* deploy constructor to deploy the new code.
*
* @param string $payload The JSON encoded payload data.
*/
function __construct( $payload ) {
$payload = json_decode( $_POST['payload'], true );
$name = $payload['repository']['name'];
$branch = $payload['commits'][0]['branch'];
if ( isset( parent::$repos[ $name ] ) ) {
$data = parent::$repos[ $name ];
$data['commit'] = $payload['commits'][0]['node'];
$data['message'] = $payload['commits'][0]['message'];
if (is_array($data['branch'])) {
foreach ($data['branch'] as $br => $pa) {
if (strpos($branch, $br) === 0 ) {
$data['path'] = $pa;
$data['branch'] = $branch;
parent::__construct( $name, $data );
return;
}
}
} else if (strpos($branch, $data['branch']) === 0) {
$data['branch'] = $branch;
parent::__construct($name, $data);
return;
}
$this->log( "Branch " . $branch . " not found in config." );
}
$this->log( "Repository " . $name . " not found in config." );
}
}
// Start the deploy attempt.
new BitBucket_Deploy( $_POST['payload'] );