Skip to content

Commit f4a5e6a

Browse files
authored
Merge pull request #7 from reallyli/support-deployed-webhook
支持部署完成的 Webhook 通知
2 parents 07c2ec6 + 1e7c976 commit f4a5e6a

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/task/notification.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,26 @@ function sendHttpRequest($url, $formParams)
2222
return curl_exec($ch);
2323
}
2424

25-
function sendGroupMessage($subject)
25+
function sendDeployNotification($subject)
2626
{
2727
$url = get('notify_channel_url');
2828

2929
if (! $url) {
30-
throw new \InvalidArgumentException('[Laravel-Deployer]Notification is on but channel url is not set!');
30+
throw new \UnexpectedValueException('[Laravel-Deployer] Not found webhook url!');
3131
}
3232

3333
$notifyBy = get('notify_by', 'webhook');
3434

3535
switch ($notifyBy) {
3636
case 'wechat_bot':
37+
$content = ''.get('environment').' 环境更新 '.get('branch').' 分支 ';
3738
$formParams = [
3839
'msgtype' => 'news',
3940
'news' => [
4041
'articles' => [
4142
[
4243
'title' => get('user').' '.$subject,
43-
'description' => ''.get('environment').' 环境更新 '.get('branch').' 分支 ',
44+
'description' => $content,
4445
'url' => get('app_repo_url', 'https://github.com'),
4546
'picurl' => get('pic_url', 'https://picsum.photos/id/'.rand(1, 1000).'/800/600'),
4647
],
@@ -60,13 +61,30 @@ function sendGroupMessage($subject)
6061
break;
6162
}
6263

63-
return get('group_notify') ? sendHttpRequest($url, $formParams) : writeln($content);
64+
if (get('group_notify')) {
65+
sendHttpRequest($url, $formParams);
66+
}
67+
68+
$deployedWebookUrl = get('deployed_webhook_url');
69+
70+
if ($deployedWebookUrl) {
71+
$deployedData = [
72+
'application' => get('application'),
73+
'user' => get('user'),
74+
'branch' => get('branch'),
75+
'environment' => get('environment'),
76+
'app_repo_url' => get('app_repo_url', 'https://github.com'),
77+
];
78+
sendHttpRequest($deployedWebookUrl, $deployedData);
79+
}
80+
81+
return writeln($content);
6482
}
6583

6684
task('success:notify', function () {
67-
return sendGroupMessage('成功发布新版本!');
85+
return sendDeployNotification('成功发布新版本!');
6886
})->local();
6987

7088
task('failed:notify', function () {
71-
return sendGroupMessage('发布新版本失败!');
89+
return sendDeployNotification('发布新版本失败!');
7290
})->local();

0 commit comments

Comments
 (0)