From ba0bf664316a4aafbe1ef878ac52e80751ed88ac Mon Sep 17 00:00:00 2001 From: lizhuangzhuang Date: Wed, 28 Aug 2019 14:31:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=9A=84=20Webhook=20=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task/notification.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/task/notification.php b/src/task/notification.php index 9398bed..05155ae 100644 --- a/src/task/notification.php +++ b/src/task/notification.php @@ -22,25 +22,26 @@ function sendHttpRequest($url, $formParams) return curl_exec($ch); } -function sendGroupMessage($subject) +function sendDeployNotification($subject) { $url = get('notify_channel_url'); if (! $url) { - throw new \InvalidArgumentException('[Laravel-Deployer]Notification is on but channel url is not set!'); + throw new \UnexpectedValueException('[Laravel-Deployer] Not found webhook url!'); } $notifyBy = get('notify_by', 'webhook'); switch ($notifyBy) { case 'wechat_bot': + $content = '在 '.get('environment').' 环境更新 '.get('branch').' 分支 '; $formParams = [ 'msgtype' => 'news', 'news' => [ 'articles' => [ [ 'title' => get('user').' '.$subject, - 'description' => '在 '.get('environment').' 环境更新 '.get('branch').' 分支 ', + 'description' => $content, 'url' => get('app_repo_url', 'https://github.com'), 'picurl' => get('pic_url', 'https://picsum.photos/id/'.rand(1, 1000).'/800/600'), ], @@ -60,13 +61,30 @@ function sendGroupMessage($subject) break; } - return get('group_notify') ? sendHttpRequest($url, $formParams) : writeln($content); + if (get('group_notify')) { + sendHttpRequest($url, $formParams); + } + + $deployedWebookUrl = get('deployed_webhook_url'); + + if ($deployedWebookUrl) { + $deployedData = [ + 'application' => get('application'), + 'user' => get('user'), + 'branch' => get('branch'), + 'environment' => get('environment'), + 'app_repo_url' => get('app_repo_url', 'https://github.com') + ]; + sendHttpRequest($deployedWebookUrl, $deployedData); + } + + return writeln($content); } task('success:notify', function () { - return sendGroupMessage('成功发布新版本!'); + return sendDeployNotification('成功发布新版本!'); })->local(); task('failed:notify', function () { - return sendGroupMessage('发布新版本失败!'); + return sendDeployNotification('发布新版本失败!'); })->local(); From ee108e1aa42303f21a830ede0d00bac3eaedaa4c Mon Sep 17 00:00:00 2001 From: reallyli Date: Wed, 28 Aug 2019 06:35:17 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/task/notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/task/notification.php b/src/task/notification.php index 05155ae..698d1e5 100644 --- a/src/task/notification.php +++ b/src/task/notification.php @@ -73,7 +73,7 @@ function sendDeployNotification($subject) 'user' => get('user'), 'branch' => get('branch'), 'environment' => get('environment'), - 'app_repo_url' => get('app_repo_url', 'https://github.com') + 'app_repo_url' => get('app_repo_url', 'https://github.com'), ]; sendHttpRequest($deployedWebookUrl, $deployedData); }