/** * Run the Slack plugin. * @return bool */ public function execute() { $message = $this->phpci->interpolate($this->message); $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' => $message, 'pretext' => $message, 'color' => $color, 'fields' => array(new \Maknz\Slack\AttachmentField(array('title' => 'Status', 'value' => $status, 'short' => false))))); $client = new \Maknz\Slack\Client($this->webHook); if (!empty($this->room)) { $client->setChannel($this->room); } if (!empty($this->username)) { $client->setUsername($this->username); } if (!empty($this->icon)) { $client->setIcon($this->icon); } $client->attach($attachment); $success = true; $client->send(''); // FIXME: Handle errors return $success; }