|
11 | 11 | task('deploy:slack', function () {
|
12 | 12 | global $php_errormsg;
|
13 | 13 |
|
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 | + ]; |
19 | 21 |
|
| 22 | + $config = array_merge($defaultConfig, (array) get('slack', [])); |
| 23 | + |
20 | 24 | $server = \Deployer\Task\Context::get()->getServer()->getConfiguration();
|
21 |
| - $host = $server->getHost(); |
22 | 25 | $user = !$server->getUser() ? null : $server->getUser();
|
23 | 26 | $messagePlaceHolders = [
|
24 | 27 | '{{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', |
30 | 33 | ];
|
31 | 34 | $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 | + |
41 | 36 | if (!is_array($config) ||
|
42 | 37 | !isset($config['token']) ||
|
43 | 38 | !isset($config['team']) ||
|
44 | 39 | !isset($config['channel']))
|
45 | 40 | {
|
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']);"); |
47 | 42 | }
|
48 | 43 |
|
49 | 44 | $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'], |
54 | 49 | 'icon_emoji' => $config['icon'],
|
55 |
| - 'pretty' => true |
| 50 | + 'pretty' => true |
56 | 51 | ];
|
57 | 52 |
|
58 | 53 | if (isset($config['icon_url'])) {
|
|
0 commit comments