Created
February 26, 2010 06:53
-
-
Save kellishaver/315489 to your computer and use it in GitHub Desktop.
monitors a github repo/branch and pulls new code when it detects a change
This file contains 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 | |
/* | |
A small script to authenticate to github, check a repo/branch | |
and pull the code if a new commit has been made. It also does | |
an initial pull as soon as it's executed. | |
Dead Simple, but it works. | |
$: cd <your repo> | |
$: php updater.php | |
Then ignore it while you work and hit Ctrl+C to break when | |
you're done or toss it into a background process and let it | |
loop forever. Just be sure to start it from within your | |
repo's base directory and that you run it as the same user | |
who owns the repo. | |
*/ | |
$username = ''; // Your Github username | |
$token = ''; // Your Github API token | |
$repository = ''; // Your repository name | |
$branch = 'master'; // The branch you're checking | |
$check = 180; // Seconds between checks | |
$prev_commit = ''; // Might as well leave it blank. | |
$loop_forever = true; // And don't change this. | |
while($loop_forever) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://github.com/api/v2/xml/commits/list/'.$username.'/'.$repository.'/'.$branch); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, 'login='.$username.'&token='.$token); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
$xml = simplexml_load_string($output); | |
$last_commit = (string) $xml->commit[0]->id; | |
if($last_commit == $prev_commit) { | |
echo date('m-d-Y H:i:s').": No change...\n"; | |
} else { | |
echo date('m-d-Y H:i:s').": Pulling: ".$last_commit."\n"; | |
exec('git pull -q origin '.$branch); | |
$prev_commit = $last_commit; | |
} | |
sleep($check); | |
} | |
date('m-d-Y H:i:s').": Exiting..."; // Probably never happen. | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment