예제 #1
0
 /**
  * Copies files from the root of the build directory into the target folder
  */
 public function execute()
 {
     if (empty($this->webhookUrl)) {
         $this->phpci->logFailure('You must specify a webhook URL.');
         return false;
     }
     $http = new HttpClient();
     $response = $http->post($this->webhookUrl, array('reason' => $this->phpci->interpolate($this->reason), 'source' => 'PHPCI', 'url' => $this->phpci->interpolate('%BUILD_URI%'), 'branch' => $this->phpci->interpolate('%BRANCH%'), 'update_only' => $this->updateOnly));
     return $response['success'];
 }
예제 #2
0
 /**
  * Github redirects users back to this URL when t
  */
 public function githubCallback()
 {
     $code = $this->getParam('code', null);
     $github = $this->settings['phpci']['github'];
     if (!is_null($code)) {
         $http = new HttpClient();
         $url = 'https://github.com/login/oauth/access_token';
         $params = array('client_id' => $github['id'], 'client_secret' => $github['secret'], 'code' => $code);
         $resp = $http->post($url, $params);
         if ($resp['success']) {
             parse_str($resp['body'], $resp);
             $this->settings['phpci']['github']['token'] = $resp['access_token'];
             $this->storeSettings();
             header('Location: ' . PHPCI_URL . 'settings?linked=1');
             die;
         }
     }
     header('Location: ' . PHPCI_URL . 'settings?linked=2');
     die;
 }
예제 #3
0
 /**
  * Run Telegram plugin.
  * @return bool
  */
 public function execute()
 {
     $build_icon = $this->build->isSuccessful() ? '✅' : '❎';
     $buildMsg = $this->build->getLog();
     $buildMsg = str_replace(array('[0;32m', '[0;31m', '[0m', '/[0m'), array('', '', ''), $buildMsg);
     $buildmessages = explode('RUNNING PLUGIN: ', $buildMsg);
     $buildMsg = '';
     foreach ($buildmessages as $bm) {
         $pos = mb_strpos($bm, "\n");
         $firstRow = mb_substr($bm, 0, $pos);
         //skip long outputs
         if ($firstRow == 'slack_notify' || $firstRow == 'php_loc' || $firstRow == 'telegram') {
             continue;
         }
         $buildMsg .= '*RUNNING PLUGIN: ' . $firstRow . "*\n";
         $buildMsg .= $firstRow == 'composer' ? '' : '```' . mb_substr($bm, $pos) . '```';
     }
     $message = $this->phpci->interpolate(str_replace(array('%ICON_BUILD%'), array($build_icon), $this->message));
     $http = new HttpClient('https://api.telegram.org');
     $http->setHeaders(array('Content-Type: application/json'));
     $uri = '/bot' . $this->api_key . '/sendMessage';
     foreach ($this->recipients as $chat_id) {
         $params = array('chat_id' => $chat_id, 'text' => $message, 'parse_mode' => 'Markdown');
         $http->post($uri, json_encode($params));
         if ($this->send_log) {
             $params = array('chat_id' => $chat_id, 'text' => $buildMsg, 'parse_mode' => 'Markdown');
             $http->post($uri, json_encode($params));
         }
     }
     return true;
 }
예제 #4
0
 public function testPost()
 {
     $http = new HttpClient('http://echo.jsontest.com');
     $data = $http->post('/key/value', array('test' => 'x'));
     $this->assertTrue(is_array($data));
 }
예제 #5
0
 /**
  * Create a comment on a Github commit.
  * @param $repo
  * @param $commitId
  * @param $file
  * @param $line
  * @param $comment
  * @return null
  */
 public function createCommitComment($repo, $commitId, $file, $line, $comment)
 {
     $token = Config::getInstance()->get('phpci.github.token');
     if (!$token) {
         return null;
     }
     $url = '/repos/' . strtolower($repo) . '/commits/' . $commitId . '/comments';
     $params = array('body' => $comment, 'path' => $file, 'position' => $line);
     $http = new HttpClient('https://api.github.com');
     $http->setHeaders(array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Basic ' . base64_encode($token . ':x-oauth-basic')));
     $http->post($url, json_encode($params));
 }