Created
June 26, 2012 15:19
-
-
Save willmot/2996390 to your computer and use it in GitHub Desktop.
Revisions
-
willmot revised this gist
Jul 4, 2012 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,8 @@ if ( ! isset( $_POST['payload'] ) ) { header( 'Status: 301' ); header( 'Location: http://hmn.md/' ); exit; } @@ -29,7 +29,7 @@ $sites = array(); $sites['Human-Made-website'] = array( 'dir' => 'humanmade', 'ref' => 'master' ); -
willmot revised this gist
Jul 4, 2012 . 1 changed file with 25 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,23 @@ <?php // TODO Handle tagged releases // TODO Check current branch is checked out before pulling // TODO Store sites in separate config file // TODO Allow config file to be in folder above root. // TODO Allow updating via $_GET? // TODO Make sure sane git status before pulling? // You can't view this file directly if ( ! isset( $_POST['payload'] ) ) { header( 'Status: 301' ); header( 'Location: http://hmn.md/' ); exit; } global $github; $github = json_decode( $_POST['payload'] ); /** @@ -32,18 +33,13 @@ 'ref' => 'master' ); define( 'ABSPATH', dirname( dirname( __FILE__ ) ) ); // Check the payload is for one of the configured sites if ( isset( $sites[$github->repository->name] ) && $site = $sites[$github->repository->name] ) { // If the directory doesn't exist then bail if ( ! file_exists( ABSPATH . '/' . $site['dir'] ) ) return; $response = ''; @@ -59,25 +55,34 @@ notify( $response, $site ); } /** * Perform a git pull & git submodule update command. * * @access public * @param string $dir * @return void */ function git_pull( $dir ) { return shell_exec( 'cd ' . escshellarg( ABSPATH . '/' . $dir ) . ' ; git pull ; git submodule update --init --recursive' ); } /** * Send an email notification with details of the payload that was just auto pulled * * @access public * @param string $response * @param array $site * @return void */ function notify( $response, $site ) { global $github; mail( 'example@email.com', 'Git Callback from ' . $site['dir'], -
willmot renamed this gist
Jun 26, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
willmot created this gist
Jun 26, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,108 @@ <?php // TODO Handle tagged releases // TODO Handle auto pulling other branches // TODO Check current branch is checked out before pulling // TODO Re-write as class // TODO Store sites in separate config file // TODO Allow config file to be in folder above root or root. // TODO Allow updating via $_GET? // TODO Make sure sane git status before pulling? // You can't view this file directly if ( !isset( $_POST['payload'] ) ) { header( 'Status: 301' ); header( 'Location: http://hmn.md/' ); exit; } global $github; $github = json_decode( $_POST['payload'] ); /** * Array of sites and their github details * * Format is array( [github repo name] => array( [site directory], [pull from branch_name or tag] ); * */ $sites = array(); $sites['Human-Made-website'] = array( 'dir' => 'humanmade', 'ref' => 'master' ); $sites['Yell-Marketing-Site'] = array( 'dir' => 'yell-marketing.hmn.md', 'ref' => 'master' ); define( 'ABSPATH', dirname( dirname( __FILE__ ) ) ); // Is the payload for one of the configured sites if ( isset( $sites[$github->repository->name] ) && $site = $sites[$github->repository->name] ) { // If the directory doesn't exist then bail if ( !file_exists( ABSPATH . '/' . $site['dir'] ) ) return; $response = ''; // If we're set to pull from a branch and that branch was part of the payload if ( $site['ref'] != 'tag' && $github->ref == 'refs/heads/' . $site['ref'] ) // Then Git Pull $response = git_pull( $site['dir'] ); // Send a notification if ( $response ) notify( $response, $site ); } function git_pull( $dir ) { return shell_exec( 'cd ' . ABSPATH . '/' . $dir . ' ; git pull ; git submodule update --init --recursive' ); } function git_checkout( $ref ) { } function get_is_branch_checked_out( $branch ) { } function notify( $response, $site ) { global $github; mail( 'tom@humanmade.co.uk, joe@humanmade.co.uk', 'Git Callback from ' . $site['dir'], ' <p><a href="mailto:' . reset( $github->commits )->author->email . '">' . reset( $github->commits )->author->name . '</a> pushed to <a href="http://' . $site['dir'] . '">' . $site['dir'] . '</a></p> <p>Commit: <a href="' . reset( $github->commits )->url . '">' . reset( $github->commits )->id . '</a></p> <p>Description:</p> <p><em>' . reset( $github->commits )->message . '</em></p> <p>Response:</p> <p><em>' . $response . '</em></p> <p>Full Details:</p> <p><pre>' . print_r( $github, true ) . '</pre></p> ', 'Content-type: text/html; charset=iso-8859-1' ); }