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

Commit

Permalink
Fix slack recipe is cleaner more
Browse files Browse the repository at this point in the history
  • Loading branch information
oanhnn committed Aug 18, 2015
1 parent 2e541d9 commit d9ffd4a
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions recipes/slack.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,43 @@
task('deploy:slack', function () {
global $php_errormsg;

$config = get('slack', []);

if (!isset($config['message'])) {
$config['message'] = "Deployment to `{{host}}` on *{{stage}}* was successful\n({{release_path}})";
}
$defaultConfig = [
'channel' => '#general',
'icon' => ':sunny:',
'username' => 'Deploy',
'message' => "Deployment to `{{host}}` on *{{stage}}* was successful\n({{release_path}})",
'app' => 'app-name',
];

$config = array_merge($defaultConfig, (array) get('slack', []));

$server = \Deployer\Task\Context::get()->getServer()->getConfiguration();
$host = $server->getHost();
$user = !$server->getUser() ? null : $server->getUser();
$messagePlaceHolders = [
'{{release_path}}' => env('release_path'),
'{{host}}' => env('server.host'),
'{{stage}}' => env('stages')[0],
'{{user}}' => $user,
'{{branch}}' => env('branch'),
'{{app_name}}' => isset($config['app']) ? ['app'] : 'app-name',
'{{host}}' => env('server.host'),
'{{stage}}' => env('stages')[0],
'{{user}}' => $user,
'{{branch}}' => env('branch'),
'{{app_name}}' => isset($config['app']) ? $config['app'] : 'app-name',
];
$config['message'] = strtr($config['message'], $messagePlaceHolders);

$defaultConfig = [
'channel' => '#general',
'icon' => ':sunny:',
'username' => 'Deploy',
'message' => "Deployment to `{{host}}` on *{{stage}}* was successful\n({{release_path}})",
];

$config = array_merge($defaultConfig, $config);

if (!is_array($config) ||
!isset($config['token']) ||
!isset($config['team']) ||
!isset($config['channel']))
{
throw new \RuntimeException("Please configure new slack: set('slack', array('token' => 'xoxp...', 'team' => 'team', 'channel' => '#channel', 'messsage' => 'message to send'));");
throw new \RuntimeException("Please configure new slack: set('slack', ['token' => 'xoxp...', 'team' => 'team', 'channel' => '#channel', 'messsage' => 'message to send']);");
}

$urlParams = [
'channel' => $config['channel'],
'token' => $config['token'],
'text' => $config['message'],
'username' => $config['username'],
'channel' => $config['channel'],
'token' => $config['token'],
'text' => $config['message'],
'username' => $config['username'],
'icon_emoji' => $config['icon'],
'pretty' => true
'pretty' => true
];

if (isset($config['icon_url'])) {
Expand Down

0 comments on commit d9ffd4a

Please sign in to comment.