phpci/PHPCI/Plugin/HipchatNotify.php

100 lines
2.6 KiB
PHP
Raw Normal View History

2014-05-13 17:56:05 +02:00
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
2014-05-13 17:56:05 +02:00
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCI\Plugin;
use PHPCI\Builder;
2014-12-04 16:48:52 +01:00
use PHPCI\Helper\Lang;
2014-05-13 17:56:05 +02:00
use PHPCI\Model\Build;
use PHPCI\PluginInterface;
2014-05-13 17:56:05 +02:00
/**
* Hipchat Plugin.
*
* Send build notification in HipChat.
*
2014-05-13 17:56:05 +02:00
* @author James Inman <james@jamesinman.co.uk>
* @package PHPCI
* @subpackage Plugins
*/
class HipchatNotify implements PluginInterface
2014-05-13 17:56:05 +02:00
{
2015-02-12 15:11:58 +01:00
protected $authToken;
protected $color;
protected $notify;
2014-05-13 17:56:05 +02:00
/**
* Set up the plugin, configure options, etc.
2015-04-28 09:12:55 +02:00
*
* @param Builder $phpci
* @param Build $build
* @param array $options
2015-04-28 09:12:55 +02:00
*
* @throws \Exception
*/
2014-05-13 17:56:05 +02:00
public function __construct(Builder $phpci, Build $build, array $options = array())
{
$this->phpci = $phpci;
$this->build = $build;
$this->userAgent = "PHPCI/1.0 (+http://www.phptesting.org/)";
$this->cookie = "phpcicookie";
if (is_array($options) && isset($options['authToken']) && isset($options['room'])) {
$this->authToken = $options['authToken'];
$this->room = $options['room'];
if (isset($options['message'])) {
$this->message = $options['message'];
} else {
2014-12-04 16:48:52 +01:00
$this->message = Lang::get('x_built_at_x');
2014-05-13 17:56:05 +02:00
}
if (isset($options['color'])) {
$this->color = $options['color'];
} else {
$this->color = 'yellow';
}
if (isset($options['notify'])) {
$this->notify = $options['notify'];
} else {
$this->notify = false;
}
2014-05-13 17:56:05 +02:00
} else {
2014-12-04 16:48:52 +01:00
throw new \Exception(Lang::get('hipchat_settings'));
2014-05-13 17:56:05 +02:00
}
}
/**
2015-04-28 09:12:55 +02:00
* {@inheritDocs}
*/
2014-05-13 17:56:05 +02:00
public function execute()
{
$hipChat = new \HipChat\HipChat($this->authToken);
$message = $this->phpci->interpolate($this->message);
$result = true;
2014-05-13 17:56:05 +02:00
if (is_array($this->room)) {
foreach ($this->room as $room) {
if (!$hipChat->message_room($room, 'PHPCI', $message, $this->notify, $this->color)) {
$result = false;
}
2014-05-13 17:56:05 +02:00
}
} else {
if (!$hipChat->message_room($this->room, 'PHPCI', $message, $this->notify, $this->color)) {
$result = false;
}
2014-05-13 17:56:05 +02:00
}
return $result;
2014-05-13 17:56:05 +02:00
}
}