From 918b4deff4e630695dc8c5dc4929bee3362718b1 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 14 May 2013 17:49:39 +0100 Subject: [PATCH] Adding Github statuses integration --- PHPCI/Controller/ProjectController.php | 3 +-- PHPCI/Controller/SessionController.php | 1 + PHPCI/Model/Build.php | 9 ++++++--- PHPCI/Plugin/Composer.php | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index f39c511c..00aeecb3 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -94,7 +94,7 @@ class ProjectController extends b8\Controller $pub = file_get_contents($id . '.pub'); $prv = file_get_contents($id); - $values = array('key' => $prv, 'pubkey' => $pub); + $values = array('key' => $prv, 'pubkey' => $pub, 'token' => $_SESSION['github_token']); } $form = $this->projectForm($values); @@ -201,7 +201,6 @@ class ProjectController extends b8\Controller if(isset($_SESSION['github_token'])) { $field = new Form\Element\Select('github'); - $field->setPattern('[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+'); $field->setLabel('Choose a Github repository:'); $field->setClass('span4'); $field->setOptions($this->getGithubRepositories()); diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index 0551dd4e..bd1bfc1a 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -53,6 +53,7 @@ class SessionController extends b8\Controller public function logout() { unset($_SESSION['user_id']); + unset($_SESSION['github_token']); header('Location: /'); die; } diff --git a/PHPCI/Model/Build.php b/PHPCI/Model/Build.php index e57b8322..56b14010 100644 --- a/PHPCI/Model/Build.php +++ b/PHPCI/Model/Build.php @@ -40,7 +40,7 @@ class Build extends BuildBase if($project->getType() == 'github' && $project->getToken()) { - $url = 'https://api.github.com/repos/'.$project->getReference().'/statuses/'.$this->build->getCommitId() . '?access_token=' . $project->getToken(); + $url = 'https://api.github.com/repos/'.$project->getReference().'/statuses/'.$this->getCommitId(); $http = new \b8\HttpClient(); switch($this->getStatus()) @@ -63,8 +63,11 @@ class Build extends BuildBase break; } - $params = array('status' => $status, 'target_url' => \b8\Registry::getInstance()->get('install_url') . '/build/view/' . $this->getId()); - $http->post($url, $params); + $params = array( 'state' => $status, + 'target_url' => \b8\Registry::getInstance()->get('install_url') . '/build/view/' . $this->getId()); + + $http->setHeaders(array('Authorization: token ' . $project->getToken())); + $http->request('POST', $url, json_encode($params)); } } } diff --git a/PHPCI/Plugin/Composer.php b/PHPCI/Plugin/Composer.php index 0d470db4..ac73f7de 100644 --- a/PHPCI/Plugin/Composer.php +++ b/PHPCI/Plugin/Composer.php @@ -17,6 +17,6 @@ class Composer implements \PHPCI\Plugin public function execute() { - return $this->phpci->executeCommand(PHPCI_DIR . 'composer.phar --working-dir=' . $this->directory . ' ' . $this->action); + return $this->phpci->executeCommand(PHPCI_DIR . 'composer.phar --prefer-dist --working-dir=' . $this->directory . ' ' . $this->action); } } \ No newline at end of file