Exemplo n.º 1
0
 /**
  * Run the Slack plugin.
  * @return bool
  */
 public function execute()
 {
     $body = $this->phpci->interpolate($this->message);
     $client = new \Maknz\Slack\Client($this->webHook);
     $message = $client->createMessage();
     if (!empty($this->room)) {
         $message->setChannel($this->room);
     }
     if (!empty($this->username)) {
         $message->setUsername($this->username);
     }
     if (!empty($this->icon)) {
         $message->setIcon($this->icon);
     }
     // Include an attachment which shows the status and hide the message
     if ($this->show_status) {
         $successfulBuild = $this->build->isSuccessful();
         if ($successfulBuild) {
             $status = 'Success';
             $color = 'good';
         } else {
             $status = 'Failed';
             $color = 'danger';
         }
         // Build up the attachment data
         $attachment = new \Maknz\Slack\Attachment(array('fallback' => $body, 'pretext' => $body, 'color' => $color, 'fields' => array(new \Maknz\Slack\AttachmentField(array('title' => 'Status', 'value' => $status, 'short' => false)))));
         $message->attach($attachment);
         $body = '';
     }
     $message->send($body);
     return true;
 }
Exemplo n.º 2
0
 private function send($post, $context, $userName)
 {
     $slackUrl = Configure::read('Slack.Url');
     if ($slackUrl) {
         $postLink = '<' . Configure::read('Email.UrlRoot') . '/posts/view/' . $post['Post']['id'] . '|' . $post['Post']['title'] . '>';
         $roomLink = '<' . Configure::read('Email.UrlRoot') . '/rooms/view/' . $post['Room']['id'] . '|' . $post['Room']['name'] . '>';
         $slackMessage = "{$userName} {$context} {$postLink} in the room {$roomLink}";
         $channel = strpos($post['Room']['slack_channel'], '#') === false ? Configure::read('Slack.DefaultChannel') : trim($post['Room']['slack_channel']);
         $settings = ['username' => 'Truckr', 'channel' => $channel, 'link_names' => true];
         $client = new Maknz\Slack\Client(Configure::read('Slack.Url'), $settings);
         $message = $client->createMessage();
         $message->send($slackMessage);
     }
 }