<?php /** * This script is pretty simple. It just verifies you are trying to deploy a known project/branch * and have passed all of the required parameters. * * If its happy; it posts back to swarm's success URL with the deploy update link. * If its sad; it screams about it and attempts to post back to swarm's error URL. */ // bork if there is no config file_exists('config.php') || handleError('Missing config.php for the deploy script'); // pluck out request variable as we reference them repeatedly $review = $change = $branch = $project = $success = $fail = null; extract($_GET, EXTR_IF_EXISTS); $config = require_once('config.php'); // detailed error if a required param is missing strlen($review) || handleError('Missing required param "review"'); ctype_digit($review) || handleError('Non-numeric "review" specified'); strlen($change) || handleError('Missing required param "change"'); ctype_digit($change) || handleError('Non-numeric "change" specified'); strlen($success) || handleError('Missing required param "success"'); strlen($project) || handleError('Missing required param "project"'); strlen($branch) || handleError('Missing required param "branch"'); // verify this is a project and branch we know about $project == 'workshop' || handleError("Unrecognized project ($project) specified"); isset($config['template_workspaces'][$branch]) || handleError('Unrecognized branch specified'); // if something went wrong report back to caller if we can and then die function handleError($error) { if (isset($_GET['fail']) && strlen($_GET['fail'])) { file_get_contents($_GET['fail'] . '?error=' . rawurlencode($error)); } die($error); } // looks like we have basic configuration and required params; report success file_get_contents( $success . '?url=' . rawurlencode( 'http://' . $_SERVER['HTTP_HOST'] . '/workshop/update/' . $review . '/?change=' . $change . '&branch=' . rawurlencode($branch) ) );