-
Notifications
You must be signed in to change notification settings - Fork 54
/
github.php
39 lines (35 loc) · 1.22 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
<?php
// Make sure we have a payload, stop if we do not.
$payload = file_get_contents( 'php://input' );
if ( empty( $payload ) )
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.
* @param array $headers Array with all the HTTP headers from the current request.
*/
function __construct( $_payload, $headers ) {
$payload = json_decode( $_payload );
$name = $payload->repository->name;
$branch = basename( $payload->ref );
$commit = substr( $payload->commits[0]->id, 0, 12 );
if ( isset( parent::$repos[ $name ] ) && parent::$repos[ $name ]['branch'] === $branch ) {
$data = parent::$repos[ $name ];
$data['commit'] = $commit;
parent::__construct( $name, $data, $_payload, $headers );
}
}
}
// Starts the deploy attempt.
new GitHub_Deploy( $payload, getallheaders() );