* @package PHPCI * @subpackage Core */ class GithubBuild extends RemoteGitBuild { /** * Get link to commit from another source (i.e. Github) */ public function getCommitLink() { return 'https://github.com/' . $this->getProject()->getReference() . '/commit/' . $this->getCommitId(); } /** * Get link to branch from another source (i.e. Github) */ public function getBranchLink() { return 'https://github.com/' . $this->getProject()->getReference() . '/tree/' . $this->getBranch(); } /** * Send status updates to any relevant third parties (i.e. Github) */ public function sendStatusPostback() { $token = \b8\Config::getInstance()->get('phpci.github.token'); if (empty($token)) { return; } $project = $this->getProject(); $url = 'https://api.github.com/repos/'.$project->getReference().'/statuses/'.$this->getCommitId(); $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; } $phpciUrl = \b8\Config::getInstance()->get('phpci.url'); $params = array( 'state' => $status, 'target_url' => $phpciUrl . '/build/view/' . $this->getId()); $headers = array( 'Authorization: token ' . $token, 'Content-Type: application/x-www-form-urlencoded' ); $http->setHeaders($headers); $http->request('POST', $url, json_encode($params)); } /** * Get the URL to be used to clone this remote repository. */ protected function getCloneUrl() { $key = trim($this->getProject()->getGitKey()); if (!empty($key)) { return 'git@github.com:' . $this->getProject()->getReference() . '.git'; } else { return 'https://github.com/' . $this->getProject()->getReference() . '.git'; } } public function getCommitMessage() { $rtn = $this->data['commit_message']; $reference = $this->getProject()->getReference(); $commitLink = '#$1'; $rtn = preg_replace('/\#([0-9]+)/', $commitLink, $rtn); $rtn = preg_replace('/\@([a-zA-Z0-9_]+)/', '@$1', $rtn); return $rtn; } public function getFileLinkTemplate() { $link = 'https://github.com/' . $this->getProject()->getReference() . '/'; $link .= 'blob/' . $this->getBranch() . '/'; $link .= '{FILE}'; $link .= '#L{LINE}'; return $link; } }