Skip to content

Instantly share code, notes, and snippets.

@tristanbes
Created April 13, 2015 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristanbes/616a1758044ac4b54206 to your computer and use it in GitHub Desktop.
Save tristanbes/616a1758044ac4b54206 to your computer and use it in GitHub Desktop.
Pull Request Builder: PHP Script which triggers Ansible Tower
$payload = $_POST['payload'];
$json = json_decode($payload);
if (isset($json->action)) {
$action = $json->action;
$prNumber = $json->pull_request->number;
switch ($action) {
case 'opened':
exec_script('scripts/build_pr.sh', array($prNumber, true));
break;
case 'synchronize':
exec_script('scripts/build_pr.sh', array($prNumber));
break;
case 'closed':
exec_script('scripts/remove_pr.sh', array($prNumber));
break;
}
} else {
if ($ref = $json->ref) {
if (preg_match('{/(v[0-9a-zA-Z]+\.[0-9a-zA-Z]+\..+)$}', $ref, $matches)) {
$version = $matches[1];
exec_script('scripts/build_release.sh', array($version));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment