Skip to content

Commit

Permalink
Add the ability to hide the slack attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
REBELinBLUE committed Oct 13, 2015
1 parent 6aea2bd commit d2ab7b3
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions PHPCI/Plugin/SlackNotify.php
Expand Up @@ -24,6 +24,7 @@ class SlackNotify implements \PHPCI\Plugin
private $username;
private $message;
private $icon;
private $show_status;

/**
* Set up the plugin, configure options, etc.
Expand Down Expand Up @@ -60,6 +61,12 @@ public function __construct(Builder $phpci, Build $build, array $options = array
$this->username = 'PHPCI';
}

if (isset($options['show_status'])) {
$this->show_status = (bool) $options['show_status'];
} else {
$this->show_status = true;
}

if (isset($options['icon'])) {
$this->icon = $options['icon'];
}
Expand All @@ -74,31 +81,7 @@ public function __construct(Builder $phpci, Build $build, array $options = array
*/
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
))
)
));
$body = $this->phpci->interpolate($this->message);

$client = new \Maknz\Slack\Client($this->webHook);

Expand All @@ -116,12 +99,40 @@ public function execute()
$message->setIcon($this->icon);
}

$message->attach($attachment);
// 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';
}

$success = true;
// 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('');
$message->send($body);

return $success;
return true;
}
}

0 comments on commit d2ab7b3

Please sign in to comment.