Skip to content
This repository was archived by the owner on Apr 26, 2020. It is now read-only.

Commit 84b3229

Browse files
Baachiantonmedv
authored andcommitted
Add rocketchat integration (#226)
1 parent f89d424 commit 84b3229

2 files changed

Lines changed: 189 additions & 0 deletions

File tree

docs/rocketchat.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# RocketChat Recipe
2+
3+
## Installing
4+
5+
Create a RocketChat incoming webhook, through the administration panel.
6+
7+
Require the new recipe into your `deploy.php`
8+
9+
```php
10+
require 'recipe/rocketchat.php';
11+
```
12+
13+
Add hook on deploy:
14+
15+
```
16+
before('deploy', 'rocketchat:notify');
17+
```
18+
19+
## Configuration
20+
21+
- `rocketchat_webhook` - incoming rocketchat webook **required**
22+
```
23+
set('rocketchat_webook', 'https://rocketchat.yourcompany.com/hooks/XXXXX');
24+
```
25+
26+
- `rocketchat_title` - the title of the application, defaults to `{{application}}`
27+
- `rocketchat_text` - notification message
28+
```
29+
set('rocketchat_text', '_{{user}}_ deploying {{branch}} to {{target}}');
30+
```
31+
32+
- `rocketchat_success_text` – success template, default:
33+
```
34+
set('rocketchat_success_text', 'Deploy to *{{target}}* successful');
35+
```
36+
- `rocketchat_failure_text` – failure template, default:
37+
```
38+
set('rocketchat_failure_text', 'Deploy to *{{target}}* failed');
39+
```
40+
41+
- `rocketchat_color` – color's attachment
42+
- `rocketchat_success_color` – success color's attachment
43+
- `rocketchat_failure_color` – failure color's attachment
44+
45+
## Tasks
46+
47+
- `rocketchat:notify` – send message to rocketchat
48+
- `rocketchat:notify:success` – send success message to rocketchat
49+
- `rocketchat:notify:failure` – send failure message to rocketchat
50+
51+
## Usage
52+
53+
If you want to notify only about beginning of deployment add this line only:
54+
55+
```php
56+
before('deploy', 'rocketchat:notify');
57+
```
58+
59+
If you want to notify about successful end of deployment add this too:
60+
61+
```php
62+
after('success', 'rocketchat:notify:success');
63+
```
64+
65+
If you want to notify about failed deployment add this too:
66+
67+
```php
68+
after('deploy:failed', 'rocketchat:notify:failure');
69+
```

recipe/rocketchat.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/* (c) Markus Bachmann <markus.bachmann@bachi.biz>
3+
*
4+
* For the full copyright and license information, please view the LICENSE
5+
* file that was distributed with this source code.
6+
*/
7+
namespace Deployer;
8+
9+
use Deployer\Utility\Httpie;
10+
11+
set('rockchat_title', function() {
12+
return get('application', 'Project');
13+
});
14+
15+
set('rocketchat_icon_emoji', ':robot:');
16+
set('rocketchat_icon_url', null);
17+
18+
set('rocketchat_channel', null);
19+
set('rocketchat_room_id', null);
20+
set('rocketchat_username', null);
21+
set('rocketchat_webhook', null);
22+
23+
set('rocketchat_color', '#000000');
24+
set('rocketchat_success_color', '#00c100');
25+
set('rocketchat_failure_color', '#ff0909');
26+
27+
set('rocketchat_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
28+
set('rocketchat_success_text', 'Deploy to *{{target}}* successful');
29+
set('rocketchat_failure_text', 'Deploy to *{{target}}* failed');
30+
31+
desc('Notify RocketChat');
32+
task('rocketchat:notify', function() {
33+
if (null === get('rocketchat_webhook')) {
34+
return;
35+
}
36+
37+
$body = [
38+
'text' => get('rockchat_title'),
39+
'username' => get('rocketchat_username'),
40+
'attachments' => [[
41+
'text' => get('rocketchat_text'),
42+
'color' => get('rocketchat_color'),
43+
]]
44+
];
45+
46+
if (get('rocketchat_channel')) {
47+
$body['channel'] = get('rocketchat_channel');
48+
}
49+
if (get('rocketchat_room_id')) {
50+
$body['roomId'] = get('rocketchat_room_id');
51+
}
52+
if (get('rocketchat_icon_url')) {
53+
$body['avatar'] = get('rocketchat_icon_url');
54+
} elseif (get('rocketchat_icon_emoji')) {
55+
$body['emoji'] = get('rocketchat_icon_emoji');
56+
}
57+
58+
Httpie::post(get('rocketchat_webhook'))->body($body)->send();
59+
});
60+
61+
desc('Notifying RocketChat about deploy finish');
62+
task('rocketchat:notify:success', function() {
63+
if (null === get('rocketchat_webhook')) {
64+
return;
65+
}
66+
67+
$body = [
68+
'text' => get('rockchat_title'),
69+
'username' => get('rocketchat_username'),
70+
'attachments' => [[
71+
'text' => get('rocketchat_success_text'),
72+
'color' => get('rocketchat_success_color'),
73+
]]
74+
];
75+
76+
if (get('rocketchat_channel')) {
77+
$body['channel'] = get('rocketchat_channel');
78+
}
79+
if (get('rocketchat_room_id')) {
80+
$body['roomId'] = get('rocketchat_room_id');
81+
}
82+
if (get('rocketchat_icon_url')) {
83+
$body['avatar'] = get('rocketchat_icon_url');
84+
} elseif (get('rocketchat_icon_emoji')) {
85+
$body['emoji'] = get('rocketchat_icon_emoji');
86+
}
87+
88+
Httpie::post(get('rocketchat_webhook'))->body($body)->send();
89+
});
90+
91+
desc('Notifying RocketChat about deploy failure');
92+
task('rocketchat:notify:failure', function() {
93+
if (null === get('rocketchat_webhook')) {
94+
return;
95+
}
96+
97+
$body = [
98+
'text' => get('rockchat_title'),
99+
'username' => get('rocketchat_username'),
100+
'attachments' => [[
101+
'color' => get('rocketchat_failure_color'),
102+
'text' => get('rocketchat_failure_text')
103+
]]
104+
];
105+
106+
if (get('rocketchat_channel')) {
107+
$body['channel'] = get('rocketchat_channel');
108+
}
109+
if (get('rocketchat_room_id')) {
110+
$body['roomId'] = get('rocketchat_room_id');
111+
}
112+
if (get('rocketchat_icon_url')) {
113+
$body['avatar'] = get('rocketchat_icon_url');
114+
} elseif (get('rocketchat_icon_emoji')) {
115+
$body['emoji'] = get('rocketchat_icon_emoji');
116+
}
117+
118+
Httpie::post(get('rocketchat_webhook'))->body($body)->send();
119+
});
120+

0 commit comments

Comments
 (0)