Skip to content
This repository was archived by the owner on Apr 26, 2020. It is now read-only.

Commit d889eb4

Browse files
lucasmezencioantonmedv
authored andcommitted
Add Discord recipe (#177)
* Add psr-4 autoload * Add default messaging * Add Discord recipe * Update docs * Remove psr-4 autoloading * Attach Discord Messaging class into Discord recipe * Remove classes and namespaces * Update readme
1 parent 375c213 commit d889eb4

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

docs/discord.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Discord recipe
2+
3+
## Installing
4+
5+
Require discord recipe in your `deploy.php` file:
6+
7+
```php
8+
require 'recipe/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+
```php
24+
[
25+
'text' => ':information_source: **{{user}}** is deploying branch `{{branch}}` to _{{target}}_',
26+
]
27+
```
28+
- `discord_success_text` – success template, default:
29+
```php
30+
[
31+
'text' => ':white_check_mark: Branch `{{branch}}` deployed to _{{target}}_ successfully',
32+
]
33+
```
34+
- `discord_failure_text` – failure template, default:
35+
```php
36+
[
37+
'text' => ':no_entry_sign: Branch `{{branch}}` has failed to deploy to _{{target}}_',
38+
]
39+
40+
## Tasks
41+
42+
- `discord:notify` – Notify Discord
43+
- `discord:notify:success` – Notify Discord about deploy finish
44+
- `discord:notify:failure` – Notify Discord about deploy failure
45+
- `discord:test` – Just notify your Discord channel with all messages, without deploying
46+
47+
## Usage
48+
49+
If you want to notify only about beginning of deployment add this line only:
50+
51+
```php
52+
before('deploy', 'discord:notify');
53+
```
54+
55+
If you want to notify about successful end of deployment add this too:
56+
57+
```php
58+
after('success', 'discord:notify:success');
59+
```
60+
61+
If you want to notify about failed deployment add this too:
62+
63+
```php
64+
after('deploy:failed', 'discord:notify:failure');
65+
```

recipe/discord.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/* (c) Lucas Mezêncio <lucas.mezencio@gmail.com>
3+
*
4+
* For the full copyright and license information, please view the LICENSE
5+
* file that was distributed with this source code.
6+
*/
7+
8+
use Deployer\Task\Context;
9+
use Deployer\Utility\Httpie;
10+
11+
set('discord_webhook', function () {
12+
return 'https://discordapp.com/api/webhooks/{{discord_channel}}/{{discord_token}}/slack';
13+
});
14+
15+
// Deploy messages
16+
set('discord_notify_text', [
17+
'text' => ':information_source: **{{user}}** is deploying branch `{{branch}}` to _{{target}}_',
18+
]);
19+
set('discord_success_text', [
20+
'text' => ':white_check_mark: Branch `{{branch}}` deployed to _{{target}}_ successfully',
21+
]);
22+
set('discord_failure_text', [
23+
'text' => ':no_entry_sign: Branch `{{branch}}` has failed to deploy to _{{target}}_',
24+
]);
25+
26+
// Helpers
27+
set('send_message', function ($data) {
28+
Httpie::post(get('discord_webhook'))->body($data)->send();
29+
});
30+
31+
// Tasks
32+
desc('Just notify your Discord channel with all messages, without deploying');
33+
task('discord:test', function () {
34+
$notify = get('discord_notify_text');
35+
$success = get('discord_success_text');
36+
$failure = get('discord_failure_text');
37+
38+
get('send_message')($notify);
39+
get('send_message')($success);
40+
get('send_message')($failure);
41+
})
42+
->once()
43+
->shallow();
44+
45+
desc('Notify Discord');
46+
task('discord:notify', function () {
47+
get('send_message')(get('discord_notify_text'));
48+
})
49+
->once()
50+
->shallow()
51+
->isPrivate();
52+
53+
desc('Notify Discord about deploy finish');
54+
task('discord:notify:success', function () {
55+
get('send_message')(get('discord_success_text'));
56+
})
57+
->once()
58+
->shallow()
59+
->isPrivate();
60+
61+
desc('Notify Discord about deploy failure');
62+
task('discord:notify:failure', function () {
63+
get('send_message')(get('discord_failure_text'));
64+
})
65+
->once()
66+
->shallow()
67+
->isPrivate();

0 commit comments

Comments
 (0)