forked from lkwdwrd/git-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.php
51 lines (47 loc) · 1.61 KB
/
github.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
51
<?php
$post = file_get_contents("php://input");
// Make sure we have a payload, stop if we do not.
if( ! isset( $post ) )
die( '<h1>No payload present</h1><p>A GitHub 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 GitHub git repos
*/
class GitHub_Deploy extends Deploy {
/**
* Decodes and validates the data from github and calls the
* deploy constructor to deploy the new code.
*
* @param string $payload The JSON encoded payload data.
*/
function __construct( $payload ) {
$payload = json_decode( $payload );
if (!isset($payload->repository)) die( '<h1>Invalid payload present</h1><p>A GitHub POST payload is required to deploy from this script.</p>' );
$name = $payload->repository->name;
$branch = basename( $payload->ref );
$commit = substr( $payload->commits[0]->id, 0, 12 );
$this->log( $branch );
if ( isset( parent::$repos[ $name ] ) ) {
$data = parent::$repos[ $name ];
$data['commit'] = $commit;
if (is_array($data['branch'])) {
foreach ($data['branch'] as $br => $pa) {
if (strpos($branch, $br) === 0 ) {
$data['path'] = $pa;
parent::__construct( $name, $data );
return;
}
}
} else if (strpos($branch, $data['branch']) === 0) {
parent::__construct($name, $data);
return;
}
}
}
}
// Starts the deploy attempt.
new GitHub_Deploy( $post );