-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from reallyli/add-wechat-bot-notification
支持企业微信机器人的 webhook
- Loading branch information
Showing
11 changed files
with
1,085 additions
and
978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Deployer; | ||
|
||
function sendHttpRequest($url, $formParams) | ||
{ | ||
$formParams = json_encode($formParams); | ||
|
||
$ch = curl_init($url); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $formParams); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt( | ||
$ch, | ||
CURLOPT_HTTPHEADER, | ||
[ | ||
'Content-Type: application/json', | ||
'Content-Length: '.strlen($formParams), | ||
] | ||
); | ||
|
||
return curl_exec($ch); | ||
} | ||
|
||
function sendGroupMessage($subject) | ||
{ | ||
$url = get('notify_channel_url'); | ||
|
||
if (! $url) { | ||
throw new \InvalidArgumentException('[Laravel-Deployer]Notification is on but channel url is not set!'); | ||
} | ||
|
||
$notifyBy = get('notify_by', 'webhook'); | ||
|
||
switch ($notifyBy) { | ||
case 'wechat_bot': | ||
$formParams = [ | ||
'msgtype' => 'news', | ||
'news' => [ | ||
'articles' => [ | ||
[ | ||
'title' => get('user').' '.$subject, | ||
'description' => '在 '.get('environment').' 环境更新 '.get('branch').' 分支 ', | ||
'url' => get('app_repo_url', 'https://github.com'), | ||
'picurl' => get('pic_url', 'https://picsum.photos/id/'.rand(1, 1000).'/800/600'), | ||
], | ||
], | ||
], | ||
]; | ||
break; | ||
default: | ||
$content = implode("\n", [ | ||
$subject, | ||
'应用名称: '.get('application'), | ||
'发布者: '.get('user'), | ||
'分支名: '.get('branch'), | ||
'环境: '.get('environment'), | ||
]); | ||
$formParams = ['text' => $content]; | ||
break; | ||
} | ||
|
||
return get('group_notify') ? sendHttpRequest($url, $formParams) : writeln($content); | ||
} | ||
|
||
task('success:notify', function () { | ||
return sendGroupMessage('成功发布新版本!'); | ||
})->local(); | ||
|
||
task('failed:notify', function () { | ||
return sendGroupMessage('发布新版本失败!'); | ||
})->local(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters