@@ -22,25 +22,26 @@ function sendHttpRequest($url, $formParams)
22
22
return curl_exec ($ ch );
23
23
}
24
24
25
- function sendGroupMessage ($ subject )
25
+ function sendDeployNotification ($ subject )
26
26
{
27
27
$ url = get ('notify_channel_url ' );
28
28
29
29
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! ' );
31
31
}
32
32
33
33
$ notifyBy = get ('notify_by ' , 'webhook ' );
34
34
35
35
switch ($ notifyBy ) {
36
36
case 'wechat_bot ' :
37
+ $ content = '在 ' .get ('environment ' ).' 环境更新 ' .get ('branch ' ).' 分支 ' ;
37
38
$ formParams = [
38
39
'msgtype ' => 'news ' ,
39
40
'news ' => [
40
41
'articles ' => [
41
42
[
42
43
'title ' => get ('user ' ).' ' .$ subject ,
43
- 'description ' => ' 在 ' . get ( ' environment ' ). ' 环境更新 ' . get ( ' branch ' ). ' 分支 ' ,
44
+ 'description ' => $ content ,
44
45
'url ' => get ('app_repo_url ' , 'https://github.com ' ),
45
46
'picurl ' => get ('pic_url ' , 'https://picsum.photos/id/ ' .rand (1 , 1000 ).'/800/600 ' ),
46
47
],
@@ -60,13 +61,30 @@ function sendGroupMessage($subject)
60
61
break ;
61
62
}
62
63
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 );
64
82
}
65
83
66
84
task ('success:notify ' , function () {
67
- return sendGroupMessage ('成功发布新版本! ' );
85
+ return sendDeployNotification ('成功发布新版本! ' );
68
86
})->local ();
69
87
70
88
task ('failed:notify ' , function () {
71
- return sendGroupMessage ('发布新版本失败! ' );
89
+ return sendDeployNotification ('发布新版本失败! ' );
72
90
})->local ();
0 commit comments