Created
September 8, 2012 23:26
-
-
Save thinkstylestudio/3680991 to your computer and use it in GitHub Desktop.
Revisions
-
thinkstylestudio revised this gist
Sep 8, 2012 . No changes.There are no files selected for viewing
-
thinkstylestudio created this gist
Sep 8, 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,51 @@ <?php // Set these dependant on your BB credentials $username = 'username'; $password = 'password'; // Grab the data from BB's POST service and decode $json = stripslashes($_POST['payload']); $data = json_decode($json); // Set some parameters to fetch the correct files $uri = $data->repository->absolute_url; $node = $data->commits[0]->node; $files = $data->commits[0]->files; // Foreach through the files and curl them over foreach ($files as $file) { if ($file->type == "removed") { unlink($file->file); } else { $url = "https://api.bitbucket.org/1.0/repositories".$uri."raw/".$node."/".$file->file; $path = $file->file; $dirname = dirname($path); if (!is_dir($dirname)){ mkdir($dirname, 0775, true); } $fp = fopen($path, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); } }