+// check blog post: http://blog.ms07.at/?p=374
+define('BITBUCKET_USER', 'XXX');
+define('BITBUCKET_API_KEY', 'XXX');
+function result($data) {
+ header('content-type: text/json');
+ echo json_encode($data);
+$json = @json_decode(file_get_contents('php://input'), true);
+$build = $json['build'];
+// SUCCESSFUL || FAILED || INPROGRESS
+switch ($build['status']) {
+ case 'infrastructure_failure':
+ 'error' => $build['status'] ?: 'Failed to get Build Data'
+if (!empty($_GET['message'])) {
+ $message = $_GET['message'];
+ $message = 'status update';
+ 'name' => 'Codeship Tests',
+ 'url' => $build['build_url'],
+ 'description' => $message
+ 'https://api.bitbucket.org/2.0/repositories/%s/commit/%s/statuses/build',
+ $build['project_name'],
+ 'Content-type: application/json',
+ 'Authorization: Basic '.base64_encode(BITBUCKET_USER.':'.BITBUCKET_API_KEY)
+ 'content' => json_encode($data)
+$context = stream_context_create($opts);
+$result = file_get_contents($url, false, $context);
+$data = @json_decode($result, true);
+ 'error' => $build['status']