Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07c2ec6

Browse files
Merge pull request #5 from reallyli/add-wechat-bot-notification
支持企业微信机器人的 webhook
2 parents 9796711 + d27c210 commit 07c2ec6

File tree

11 files changed

+1085
-978
lines changed

11 files changed

+1085
-978
lines changed

‎composer.json‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
"php": "^7.1.3",
1414
"deployer/deployer": "^6.1",
1515
"deployer/recipes": "^6.0",
16-
"illuminate/support": "^5.5"
16+
"illuminate/support": "5.5.*"
1717
},
1818
"require-dev": {
19-
"mockery/mockery": "^1.0",
20-
"codedungeon/phpunit-result-printer": "^0.19.13",
21-
"phpunit/phpunit": "^7.0"
19+
"orchestra/testbench": "^3.5",
20+
"phpunit/phpunit": "^6.0"
2221
},
2322
"autoload": {
2423
"psr-4": {

‎composer.lock‎

Lines changed: 987 additions & 904 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎deploy.yml.sample‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ options:
1717
shared_dirs: null
1818
log_file_name: laravel.log
1919
log_lines: 200
20+
notify_by: wechat_bot
21+
app_repo_url: https://github.com
2022
hosts: []
2123
localhost: []
2224
include: []

‎phpunit.xml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
99
processIsolation="false"
10-
stopOnFailure="false"
11-
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
10+
stopOnFailure="false">
1211
<filter>
1312
<whitelist processUncoveredFilesFromWhitelist="true">
1413
<directory suffix=".php">

‎src/recipe/laravel-deployer.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
require 'task/init.php';
19-
require 'task/notify.php';
19+
require 'task/notification.php';
2020

2121
require 'task/defaults.php';
2222
require 'task/helpers.php';

‎src/task/notification.php‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Deployer;
4+
5+
function sendHttpRequest($url, $formParams)
6+
{
7+
$formParams = json_encode($formParams);
8+
9+
$ch = curl_init($url);
10+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
11+
curl_setopt($ch, CURLOPT_POSTFIELDS, $formParams);
12+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
13+
curl_setopt(
14+
$ch,
15+
CURLOPT_HTTPHEADER,
16+
[
17+
'Content-Type: application/json',
18+
'Content-Length: '.strlen($formParams),
19+
]
20+
);
21+
22+
return curl_exec($ch);
23+
}
24+
25+
function sendGroupMessage($subject)
26+
{
27+
$url = get('notify_channel_url');
28+
29+
if (! $url) {
30+
throw new \InvalidArgumentException('[Laravel-Deployer]Notification is on but channel url is not set!');
31+
}
32+
33+
$notifyBy = get('notify_by', 'webhook');
34+
35+
switch ($notifyBy) {
36+
case 'wechat_bot':
37+
$formParams = [
38+
'msgtype' => 'news',
39+
'news' => [
40+
'articles' => [
41+
[
42+
'title' => get('user').''.$subject,
43+
'description' => ''.get('environment').' 环境更新 '.get('branch').' 分支 ',
44+
'url' => get('app_repo_url', 'https://github.com'),
45+
'picurl' => get('pic_url', 'https://picsum.photos/id/'.rand(1, 1000).'/800/600'),
46+
],
47+
],
48+
],
49+
];
50+
break;
51+
default:
52+
$content = implode("\n", [
53+
$subject,
54+
'应用名称: '.get('application'),
55+
'发布者: '.get('user'),
56+
'分支名: '.get('branch'),
57+
'环境: '.get('environment'),
58+
]);
59+
$formParams = ['text' => $content];
60+
break;
61+
}
62+
63+
return get('group_notify') ? sendHttpRequest($url, $formParams) : writeln($content);
64+
}
65+
66+
task('success:notify', function () {
67+
return sendGroupMessage('成功发布新版本!');
68+
})->local();
69+
70+
task('failed:notify', function () {
71+
return sendGroupMessage('发布新版本失败!');
72+
})->local();

‎src/task/notify.php‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎tests/.build/deploy.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
set('strategy', 'basic');
16-
set('application', 'LaravelDeployer');
16+
set('application', 'Example');
1717
set('keep_releases', 6);
1818
set('php_fpm_service', 'php7.2-fpm');
1919
set('group_notify', false);
@@ -22,6 +22,8 @@
2222
set('shared_dirs', null);
2323
set('log_file_name', 'laravel.log');
2424
set('log_lines', 200);
25+
set('notify_by', 'wechat_bot');
26+
set('app_repo_url', 'https://github.com');
2527

2628
/*
2729
* Hosts and localhost

‎tests/Features/deploy.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ hooks:
88
success: 'record:revision:log'
99
fail: { }
1010
options:
11-
application: LaravelDeployer
11+
application: Example
1212
keep_releases: 6
1313
php_fpm_service: php7.2-fpm
1414
group_notify: false
@@ -17,6 +17,8 @@ options:
1717
shared_dirs: null
1818
log_file_name: laravel.log
1919
log_lines: 200
20+
notify_by: wechat_bot
21+
app_repo_url: 'https://github.com'
2022
hosts: { }
2123
localhost: { }
2224
include: { }

‎tests/TestCase.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ public function __construct($name = null, array $data = [], $dataName = '')
4444
parent::__construct($name, $data, $dataName);
4545
}
4646

47-
/**
48-
* sep up.
49-
*/
50-
public function setUp()
51-
{
52-
parent::setUp();
53-
}
54-
5547
/**
5648
* @param \Illuminate\Foundation\Application $app
5749
*/
@@ -68,4 +60,14 @@ protected function getPackageProviders($app)
6860
{
6961
return ['Reallyli\LaravelDeployer\LaravelDeployerServiceProvider'];
7062
}
63+
64+
public function setUp(): void
65+
{
66+
parent::setUp();
67+
}
68+
69+
public function tearDown(): void
70+
{
71+
// parent::tearDown();
72+
}
7173
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /