-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathHipchatNotify.php
More file actions
96 lines (82 loc) · 2.41 KB
/
Copy pathHipchatNotify.php
File metadata and controls
96 lines (82 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace PHPCensor\Plugin;
use HipChat\HipChat;
use PHPCensor\Builder;
use PHPCensor\Common\Exception\InvalidArgumentException;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
/**
* Hipchat Plugin
*
* @package PHP Censor
* @subpackage Application
*
* @author James Inman <james@jamesinman.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class HipchatNotify extends Plugin
{
protected $authToken;
protected $color;
protected $notify;
protected $message;
protected $room;
/**
* @return string
*/
public static function pluginName()
{
return 'hipchat_notify';
}
/**
* {@inheritDoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
if (!\is_array($options) || !isset($options['room']) || !isset($options['auth_token'])) {
throw new InvalidArgumentException('Please define room and authToken for hipchat_notify plugin.');
}
if (\array_key_exists('auth_token', $options)) {
$this->authToken = $this->builder->interpolate($options['auth_token'], true);
}
$this->room = $options['room'];
if (isset($options['message'])) {
$this->message = $options['message'];
} else {
$this->message = '%PROJECT_TITLE% built at %BUILD_LINK%';
}
if (isset($options['color'])) {
$this->color = $options['color'];
} else {
$this->color = 'yellow';
}
if (isset($options['notify'])) {
$this->notify = $options['notify'];
} else {
$this->notify = false;
}
}
/**
* Run the HipChat plugin.
* @return bool
*/
public function execute()
{
$hipChat = new HipChat($this->authToken);
$message = $this->builder->interpolate($this->message);
$result = true;
if (\is_array($this->room)) {
foreach ($this->room as $room) {
if (!$hipChat->message_room($room, 'PHP Censor', $message, $this->notify, $this->color)) {
$result = false;
}
}
} else {
if (!$hipChat->message_room($this->room, 'PHP Censor', $message, $this->notify, $this->color)) {
$result = false;
}
}
return $result;
}
}