Created
January 20, 2015 10:06
-
-
Save flashvnn/c2e25ec6620cb5c9f996 to your computer and use it in GitHub Desktop.
Bitbucket Autodeploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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( stripslashes( $_POST['payload'] ), true ); | |
| $name = $payload['repository']['name']; | |
| $this->log( $payload['commits'][0]['branch'] ); | |
| if (strpos(strtolower($payload['commits'][0]['message']), 'deploy') === FALSE) { | |
| return; | |
| } | |
| if ( isset( parent::$repos[ $name ] ) && parent::$repos[ $name ]['branch'] === $payload['commits'][0]['branch'] ) { | |
| $data = parent::$repos[ $name ]; | |
| $data['commit'] = $payload['commits'][0]['node']; | |
| parent::__construct( $name, $data ); | |
| } | |
| } | |
| } | |
| // Start the deploy attempt. | |
| new BitBucket_Deploy( $_POST['payload'] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment