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