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

Commit d9ffd4a

Browse files
author
oanhnn
committed
Fix slack recipe is cleaner more
1 parent 2e541d9 commit d9ffd4a

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

recipes/slack.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,43 @@
1111
task('deploy:slack', function () {
1212
global $php_errormsg;
1313

14-
$config = get('slack', []);
15-
16-
if (!isset($config['message'])) {
17-
$config['message'] = "Deployment to `{{host}}` on *{{stage}}* was successful\n({{release_path}})";
18-
}
14+
$defaultConfig = [
15+
'channel' => '#general',
16+
'icon' => ':sunny:',
17+
'username' => 'Deploy',
18+
'message' => "Deployment to `{{host}}` on *{{stage}}* was successful\n({{release_path}})",
19+
'app' => 'app-name',
20+
];
1921

22+
$config = array_merge($defaultConfig, (array) get('slack', []));
23+
2024
$server = \Deployer\Task\Context::get()->getServer()->getConfiguration();
21-
$host = $server->getHost();
2225
$user = !$server->getUser() ? null : $server->getUser();
2326
$messagePlaceHolders = [
2427
'{{release_path}}' => env('release_path'),
25-
'{{host}}' => env('server.host'),
26-
'{{stage}}' => env('stages')[0],
27-
'{{user}}' => $user,
28-
'{{branch}}' => env('branch'),
29-
'{{app_name}}' => isset($config['app']) ? ['app'] : 'app-name',
28+
'{{host}}' => env('server.host'),
29+
'{{stage}}' => env('stages')[0],
30+
'{{user}}' => $user,
31+
'{{branch}}' => env('branch'),
32+
'{{app_name}}' => isset($config['app']) ? $config['app'] : 'app-name',
3033
];
3134
$config['message'] = strtr($config['message'], $messagePlaceHolders);
32-
33-
$defaultConfig = [
34-
'channel' => '#general',
35-
'icon' => ':sunny:',
36-
'username' => 'Deploy',
37-
'message' => "Deployment to `{{host}}` on *{{stage}}* was successful\n({{release_path}})",
38-
];
39-
40-
$config = array_merge($defaultConfig, $config);
35+
4136
if (!is_array($config) ||
4237
!isset($config['token']) ||
4338
!isset($config['team']) ||
4439
!isset($config['channel']))
4540
{
46-
throw new \RuntimeException("Please configure new slack: set('slack', array('token' => 'xoxp...', 'team' => 'team', 'channel' => '#channel', 'messsage' => 'message to send'));");
41+
throw new \RuntimeException("Please configure new slack: set('slack', ['token' => 'xoxp...', 'team' => 'team', 'channel' => '#channel', 'messsage' => 'message to send']);");
4742
}
4843

4944
$urlParams = [
50-
'channel' => $config['channel'],
51-
'token' => $config['token'],
52-
'text' => $config['message'],
53-
'username' => $config['username'],
45+
'channel' => $config['channel'],
46+
'token' => $config['token'],
47+
'text' => $config['message'],
48+
'username' => $config['username'],
5449
'icon_emoji' => $config['icon'],
55-
'pretty' => true
50+
'pretty' => true
5651
];
5752

5853
if (isset($config['icon_url'])) {

0 commit comments

Comments
 (0)