diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 7c3c1dc1..f6e926d6 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -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)); diff --git a/PHPCI/Controller/GithubController.php b/PHPCI/Controller/GithubController.php index bd3c478d..7e1626b9 100644 --- a/PHPCI/Controller/GithubController.php +++ b/PHPCI/Controller/GithubController.php @@ -36,7 +36,8 @@ class GithubController extends b8\Controller try { - $this->_buildStore->save($build); + $build = $this->_buildStore->save($build); + $build->sendStatusPostback(); } catch(\Exception $ex) { diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index 451871e5..e7a2c915 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -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'); + } + diff --git a/PHPCI/Model/Build.php b/PHPCI/Model/Build.php index 2ce4bb35..e57b8322 100644 --- a/PHPCI/Model/Build.php +++ b/PHPCI/Model/Build.php @@ -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); + } + } } diff --git a/PHPCI/View/ProjectForm.phtml b/PHPCI/View/ProjectForm.phtml index af1c7e43..4177215a 100644 --- a/PHPCI/View/ProjectForm.phtml +++ b/PHPCI/View/ProjectForm.phtml @@ -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(); diff --git a/install.php b/install.php index 96a611ae..52da6899 100644 --- a/install.php +++ b/install.php @@ -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', "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')) {