Github pull request status updates

This commit is contained in:
Dan Cryer 2013-05-14 16:58:14 +01:00
parent dfeac39be3
commit 812dfcb95a
6 changed files with 87 additions and 7 deletions

View file

@ -28,6 +28,7 @@ class Builder
$this->build->setStatus(1);
$this->build->setStarted(new \DateTime());
$this->build = $this->store->save($this->build);
$this->build->sendStatusPostback();
if($this->setupBuild())
{
@ -60,6 +61,7 @@ class Builder
$this->removeBuild();
$this->build->sendStatusPostback();
$this->build->setFinished(new \DateTime());
$this->build->setLog($this->log);
$this->build->setPlugins(json_encode($this->plugins));

View file

@ -36,7 +36,8 @@ class GithubController extends b8\Controller
try
{
$this->_buildStore->save($build);
$build = $this->_buildStore->save($build);
$build->sendStatusPostback();
}
catch(\Exception $ex)
{

View file

@ -21,6 +21,7 @@ class ProjectBase extends Model
'reference' => null,
'git_key' => null,
'type' => null,
'token' => null,
);
protected $_getters = array(
'id' => 'getId',
@ -28,6 +29,7 @@ class ProjectBase extends Model
'reference' => 'getReference',
'git_key' => 'getGitKey',
'type' => 'getType',
'token' => 'getToken',
);
@ -38,6 +40,7 @@ class ProjectBase extends Model
'reference' => 'setReference',
'git_key' => 'setGitKey',
'type' => 'setType',
'token' => 'setToken',
);
public $columns = array(
@ -80,6 +83,14 @@ class ProjectBase extends Model
),
'token' => array(
'type' => 'varchar',
'length' => '50',
'nullable' => true,
),
);
public $indexes = array(
@ -130,6 +141,14 @@ class ProjectBase extends Model
return $rtn;
}
public function getToken()
{
$rtn = $this->_data['token'];
return $rtn;
}
public function setId($value)
@ -202,6 +221,20 @@ class ProjectBase extends Model
$this->_setModified('type');
}
public function setToken($value)
{
$this->_validateString('Token', $value);
if($this->_data['token'] == $value)
{
return;
}
$this->_data['token'] = $value;
$this->_setModified('token');
}

View file

@ -33,4 +33,38 @@ class Build extends BuildBase
return 'https://github.com/' . $this->getProject()->getReference() . '/tree/' . $this->getBranch();
}
}
public function sendStatusPostback()
{
$project = $this->getProject();
if($project->getType() == 'github' && $project->getToken())
{
$url = 'https://api.github.com/repos/'.$project->getReference().'/statuses/'.$this->build->getCommitId() . '?access_token=' . $project->getToken();
$http = new \b8\HttpClient();
switch($this->getStatus())
{
case 0:
case 1:
$status = 'pending';
break;
case 2:
$status = 'success';
break;
case 3:
$status = 'failure';
break;
default:
$status = 'error';
break;
}
$params = array('status' => $status, 'target_url' => \b8\Registry::getInstance()->get('install_url') . '/build/view/' . $this->getId());
$http->post($url, $params);
}
}
}

View file

@ -89,10 +89,7 @@ $(document).ready(function()
$('#element-reference').hide();
$('#element-type').hide();
$('#element-token').val(window.github_token);
if(!$('#element-title').val()) {
$('#element-title').val(val);
}
$('#element-title').val(val);
}
else {
$('label[for=element-reference]').show();

View file

@ -7,11 +7,14 @@ $dbHost = ask('Enter your MySQL host: ');
$dbName = ask('Enter the database name PHPCI should use: ');
$dbUser = ask('Enter your MySQL username: ');
$dbPass = ask('Enter your MySQL password: ', true);
$ciUrl = ask('Your PHPCI URL (without trailing slash): ', true);
$ghId = ask('(Optional) Github Application ID: ', true);
$ghSecret = ask('(Optional) Github Application Secret: ', true);
$cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost . ' -e "CREATE DATABASE IF NOT EXISTS ' . $dbName . '"';
shell_exec($cmd);
file_put_contents('./config.php', "<?php
$str = "<?php
define('PHPCI_DB_HOST', '{$dbHost}');
@ -19,7 +22,17 @@ b8\Database::setDetails('{$dbName}', '{$dbUser}', '{$dbPass}');
b8\Database::setWriteServers(array('{$dbHost}'));
b8\Database::setReadServers(array('{$dbHost}'));
");
\$registry = b8\Registry::getInstance();
\$registry->set('install_url', '{$ciUrl}');
";
if(!empty($ghId) && !empty($ghSecret))
{
$str .= PHP_EOL . "\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" . PHP_EOL;
}
file_put_contents('./config.php', $str);
if(!file_exists('./composer.phar'))
{