Merge 3d6655c075
into 6aea2bdb88
This commit is contained in:
commit
0c8fd4799d
|
@ -188,6 +188,14 @@ class Builder implements LoggerAwareInterface
|
||||||
$this->build->sendStatusPostback();
|
$this->build->sendStatusPostback();
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
||||||
|
$previous_build = $this->build->getProject()->getPreviousBuild($this->build->getBranch());
|
||||||
|
|
||||||
|
$previous_state = Build::STATUS_NEW;
|
||||||
|
|
||||||
|
if ($previous_build) {
|
||||||
|
$previous_state = $previous_build->getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Set up the build:
|
// Set up the build:
|
||||||
$this->setupBuild();
|
$this->setupBuild();
|
||||||
|
@ -210,9 +218,19 @@ class Builder implements LoggerAwareInterface
|
||||||
|
|
||||||
if ($success) {
|
if ($success) {
|
||||||
$this->pluginExecutor->executePlugins($this->config, 'success');
|
$this->pluginExecutor->executePlugins($this->config, 'success');
|
||||||
|
|
||||||
|
if ($previous_state == Build::STATUS_FAILED) {
|
||||||
|
$this->pluginExecutor->executePlugins($this->config, 'fixed');
|
||||||
|
}
|
||||||
|
|
||||||
$this->buildLogger->logSuccess(Lang::get('build_success'));
|
$this->buildLogger->logSuccess(Lang::get('build_success'));
|
||||||
} else {
|
} else {
|
||||||
$this->pluginExecutor->executePlugins($this->config, 'failure');
|
$this->pluginExecutor->executePlugins($this->config, 'failure');
|
||||||
|
|
||||||
|
if ($previous_state == Build::STATUS_SUCCESS || $previous_state == Build::STATUS_NEW) {
|
||||||
|
$this->pluginExecutor->executePlugins($this->config, 'broken');
|
||||||
|
}
|
||||||
|
|
||||||
$this->buildLogger->logFailure(Lang::get('build_failed'));
|
$this->buildLogger->logFailure(Lang::get('build_failed'));
|
||||||
}
|
}
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
|
|
|
@ -306,6 +306,8 @@ PHPCI',
|
||||||
'stage_complete' => 'Complete',
|
'stage_complete' => 'Complete',
|
||||||
'stage_success' => 'Success',
|
'stage_success' => 'Success',
|
||||||
'stage_failure' => 'Failure',
|
'stage_failure' => 'Failure',
|
||||||
|
'stage_broken' => 'Broken',
|
||||||
|
'stage_fixed' => 'Fixed',
|
||||||
|
|
||||||
// Installer
|
// Installer
|
||||||
'installation_url' => 'PHPCI Installation URL',
|
'installation_url' => 'PHPCI Installation URL',
|
||||||
|
|
|
@ -50,6 +50,29 @@ class Project extends ProjectBase
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the previous build from a specific branch, for this project.
|
||||||
|
* @param string $branch
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
|
public function getPreviousBuild($branch = 'master')
|
||||||
|
{
|
||||||
|
$criteria = array('branch' => $branch, 'project_id' => $this->getId());
|
||||||
|
|
||||||
|
$order = array('id' => 'DESC');
|
||||||
|
$builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, 1, array(), $order);
|
||||||
|
|
||||||
|
if (is_array($builds['items']) && count($builds['items'])) {
|
||||||
|
$previous = array_shift($builds['items']);
|
||||||
|
|
||||||
|
if (isset($previous) && $previous instanceof Build) {
|
||||||
|
return $previous;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store this project's access_information data
|
* Store this project's access_information data
|
||||||
* @param string|array $value
|
* @param string|array $value
|
||||||
|
|
|
@ -24,6 +24,7 @@ class SlackNotify implements \PHPCI\Plugin
|
||||||
private $username;
|
private $username;
|
||||||
private $message;
|
private $message;
|
||||||
private $icon;
|
private $icon;
|
||||||
|
private $show_status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the plugin, configure options, etc.
|
* Set up the plugin, configure options, etc.
|
||||||
|
@ -60,6 +61,12 @@ class SlackNotify implements \PHPCI\Plugin
|
||||||
$this->username = 'PHPCI';
|
$this->username = 'PHPCI';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($options['show_status'])) {
|
||||||
|
$this->show_status = (bool) $options['show_status'];
|
||||||
|
} else {
|
||||||
|
$this->show_status = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($options['icon'])) {
|
if (isset($options['icon'])) {
|
||||||
$this->icon = $options['icon'];
|
$this->icon = $options['icon'];
|
||||||
}
|
}
|
||||||
|
@ -74,32 +81,10 @@ class SlackNotify implements \PHPCI\Plugin
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$message = $this->phpci->interpolate($this->message);
|
$body = $this->phpci->interpolate($this->message);
|
||||||
|
|
||||||
$successfulBuild = $this->build->isSuccessful();
|
$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);
|
$client = new \Maknz\Slack\Client($this->webHook);
|
||||||
|
|
||||||
$message = $client->createMessage();
|
$message = $client->createMessage();
|
||||||
|
@ -116,12 +101,38 @@ class SlackNotify implements \PHPCI\Plugin
|
||||||
$message->setIcon($this->icon);
|
$message->setIcon($this->icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
$message->attach($attachment);
|
// Include an attachment which shows the status and hide the message
|
||||||
|
if ($this->show_status) {
|
||||||
|
|
||||||
$success = true;
|
if ($successfulBuild) {
|
||||||
|
$status = 'Success';
|
||||||
|
$color = 'good';
|
||||||
|
} else {
|
||||||
|
$status = 'Failed';
|
||||||
|
$color = 'danger';
|
||||||
|
}
|
||||||
|
|
||||||
$message->send('');
|
// 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
|
||||||
|
))
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
return $success;
|
$message->attach($attachment);
|
||||||
|
|
||||||
|
$body = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$message->send($body);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue