1 | <?php |
||
2 | namespace Deployer; |
||
3 | |||
4 | use Deployer\Task\Context; |
||
5 | use Deployer\Utility\Httpie; |
||
6 | |||
7 | set('discord_webhook', function () { |
||
8 | return 'https://discordapp.com/api/webhooks/{{discord_channel}}/{{discord_token}}/slack'; |
||
9 | }); |
||
10 | |||
11 | // Deploy messages |
||
12 | set('discord_notify_text', function() { |
||
13 | return [ |
||
14 | 'text' => parse(':information_source: **{{user}}** is deploying branch `{{branch}}` to _{{target}}_'), |
||
15 | ]; |
||
16 | }); |
||
17 | set('discord_success_text', function() { |
||
18 | return [ |
||
19 | 'text' => parse(':white_check_mark: Branch `{{branch}}` deployed to _{{target}}_ successfully'), |
||
20 | ]; |
||
21 | }); |
||
22 | set('discord_failure_text', function() { |
||
23 | return [ |
||
24 | 'text' => parse(':no_entry_sign: Branch `{{branch}}` has failed to deploy to _{{target}}_'), |
||
25 | ]; |
||
26 | }); |
||
27 | |||
28 | // The message |
||
29 | set('discord_message', 'discord_notify_text'); |
||
30 | |||
31 | // Helpers |
||
32 | task('discord_send_message', function(){ |
||
33 | $message = get(get('discord_message')); |
||
34 | |||
35 | Httpie::post(get('discord_webhook'))->body($message)->send(); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
36 | }); |
||
37 | |||
38 | // Tasks |
||
39 | desc('Just notify your Discord channel with all messages, without deploying'); |
||
40 | task('discord:test', function () { |
||
41 | set('discord_message', 'discord_notify_text'); |
||
42 | invoke('discord_send_message'); |
||
43 | set('discord_message', 'discord_success_text'); |
||
44 | invoke('discord_send_message'); |
||
45 | set('discord_message', 'discord_failure_text'); |
||
46 | invoke('discord_send_message'); |
||
47 | }) |
||
48 | ->once() |
||
49 | ->shallow(); |
||
50 | |||
51 | desc('Notify Discord'); |
||
52 | task('discord:notify', function () { |
||
53 | set('discord_message', 'discord_notify_text'); |
||
54 | invoke('discord_send_message'); |
||
55 | }) |
||
56 | ->once() |
||
57 | ->shallow() |
||
58 | ->isHidden(); |
||
59 | |||
60 | desc('Notify Discord about deploy finish'); |
||
61 | task('discord:notify:success', function () { |
||
62 | set('discord_message', 'discord_success_text'); |
||
63 | invoke('discord_send_message'); |
||
64 | }) |
||
65 | ->once() |
||
66 | ->shallow() |
||
67 | ->isHidden(); |
||
68 | |||
69 | desc('Notify Discord about deploy failure'); |
||
70 | task('discord:notify:failure', function () { |
||
71 | set('discord_message', 'discord_failure_text'); |
||
72 | invoke('discord_send_message'); |
||
73 | }) |
||
74 | ->once() |
||
75 | ->shallow() |
||
76 | ->isHidden(); |
||
77 |