forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord.php
128 lines (104 loc) · 3.18 KB
/
discord.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
## Installing
Require discord recipe in your `deploy.php` file:
```php
require 'contrib/discord.php';
```
Add hook on deploy:
```php
before('deploy', 'discord:notify');
```
## Configuration
- `discord_channel` – Discord channel ID, **required**
- `discord_token` – Discord channel token, **required**
- `discord_notify_text` – notification message template, markdown supported, default:
```markdown
:information_source: **{{user}}** is deploying branch `{{branch}}` to _{{target}}_
```
- `discord_success_text` – success template, default:
```markdown
:white_check_mark: Branch `{{branch}}` deployed to _{{target}}_ successfully
```
- `discord_failure_text` – failure template, default:
```markdown
:no_entry_sign: Branch `{{branch}}` has failed to deploy to _{{target}}_
## Usage
If you want to notify only about beginning of deployment add this line only:
```php
before('deploy', 'discord:notify');
```
If you want to notify about successful end of deployment add this too:
```php
after('success', 'discord:notify:success');
```
If you want to notify about failed deployment add this too:
```php
after('deploy:failed', 'discord:notify:failure');
```
*/
namespace Deployer;
use Deployer\Task\Context;
use Deployer\Utility\Httpie;
set('discord_webhook', function () {
return 'https://discordapp.com/api/webhooks/{{discord_channel}}/{{discord_token}}/slack';
});
// Deploy messages
set('discord_notify_text', function() {
return [
'text' => parse(':information_source: **{{user}}** is deploying branch `{{branch}}` to _{{target}}_'),
];
});
set('discord_success_text', function() {
return [
'text' => parse(':white_check_mark: Branch `{{branch}}` deployed to _{{target}}_ successfully'),
];
});
set('discord_failure_text', function() {
return [
'text' => parse(':no_entry_sign: Branch `{{branch}}` has failed to deploy to _{{target}}_'),
];
});
// The message
set('discord_message', 'discord_notify_text');
// Helpers
task('discord_send_message', function(){
$message = get(get('discord_message'));
Httpie::post(get('discord_webhook'))->body($message)->send();
});
// Tasks
desc('Just notify your Discord channel with all messages, without deploying');
task('discord:test', function () {
set('discord_message', 'discord_notify_text');
invoke('discord_send_message');
set('discord_message', 'discord_success_text');
invoke('discord_send_message');
set('discord_message', 'discord_failure_text');
invoke('discord_send_message');
})
->once()
->shallow();
desc('Notify Discord');
task('discord:notify', function () {
set('discord_message', 'discord_notify_text');
invoke('discord_send_message');
})
->once()
->shallow()
->isHidden();
desc('Notify Discord about deploy finish');
task('discord:notify:success', function () {
set('discord_message', 'discord_success_text');
invoke('discord_send_message');
})
->once()
->shallow()
->isHidden();
desc('Notify Discord about deploy failure');
task('discord:notify:failure', function () {
set('discord_message', 'discord_failure_text');
invoke('discord_send_message');
})
->once()
->shallow()
->isHidden();