forked from deployphp/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhipchat.php
63 lines (51 loc) · 1.72 KB
/
hipchat.php
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
<?php
/* (c) Stephan Wentz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
desc('Notifying Hipchat channel of deployment');
task('deploy:hipchat', function () {
global $php_errormsg;
$config = get('hipchat', []);
if (!isset($config['message'])) {
$releasePath = get('release_path');
$host = get('server.host');
$stage = get('stages')[0];
$config['message'] = "Deployment to '{$host}' on *{$stage}* was successful\n($releasePath)";
}
if (!isset($config['from'])) {
$stage = get('stages')[0];
$config['from'] = $stage;
}
$defaultConfig = [
'color' => 'green',
'format' => 'json',
'notify' => 0,
'endpoint' => 'https://api.hipchat.com/v1/rooms/message',
];
$config = array_merge($defaultConfig, $config);
if (!is_array($config) ||
!isset($config['auth_token']) ||
!isset($config['room_id']))
{
throw new \RuntimeException("Please configure new hipchat: set('hipchat', array('auth_token' => 'xxx', 'room_id' => 'yyy'));");
}
$endpoint = $config['endpoint'];
unset($config['endpoint']);
$urlParams = [
'room_id' => $config['room_id'],
'from' => $config['from'],
'message' => $config['message'],
'color' => $config['color'],
'auth_token' => $config['auth_token'],
'notify' => $config['notify'],
'format' => $config['format'],
];
$url = $endpoint . '?' . http_build_query($urlParams);
$result = @file_get_contents($url);
if (!$result) {
throw new \RuntimeException($php_errormsg);
}
});