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

Commit

Permalink
Add Discord recipe (#177)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lucasmezencio authored and antonmedv committed Apr 20, 2018
1 parent 375c213 commit d889eb4
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
65 changes: 65 additions & 0 deletions docs/discord.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Discord recipe

## Installing

Require discord recipe in your `deploy.php` file:

```php
require 'recipe/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:
```php
[
'text' => ':information_source: **{{user}}** is deploying branch `{{branch}}` to _{{target}}_',
]
```
- `discord_success_text` – success template, default:
```php
[
'text' => ':white_check_mark: Branch `{{branch}}` deployed to _{{target}}_ successfully',
]
```
- `discord_failure_text` – failure template, default:
```php
[
'text' => ':no_entry_sign: Branch `{{branch}}` has failed to deploy to _{{target}}_',
]

## Tasks

- `discord:notify` – Notify Discord
- `discord:notify:success` – Notify Discord about deploy finish
- `discord:notify:failure` – Notify Discord about deploy failure
- `discord:test` – Just notify your Discord channel with all messages, without deploying

## 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');
```
67 changes: 67 additions & 0 deletions recipe/discord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/* (c) Lucas Mezêncio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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', [
'text' => ':information_source: **{{user}}** is deploying branch `{{branch}}` to _{{target}}_',
]);
set('discord_success_text', [
'text' => ':white_check_mark: Branch `{{branch}}` deployed to _{{target}}_ successfully',
]);
set('discord_failure_text', [
'text' => ':no_entry_sign: Branch `{{branch}}` has failed to deploy to _{{target}}_',
]);

// Helpers
set('send_message', function ($data) {
Httpie::post(get('discord_webhook'))->body($data)->send();
});

// Tasks
desc('Just notify your Discord channel with all messages, without deploying');
task('discord:test', function () {
$notify = get('discord_notify_text');
$success = get('discord_success_text');
$failure = get('discord_failure_text');

get('send_message')($notify);
get('send_message')($success);
get('send_message')($failure);
})
->once()
->shallow();

desc('Notify Discord');
task('discord:notify', function () {
get('send_message')(get('discord_notify_text'));
})
->once()
->shallow()
->isPrivate();

desc('Notify Discord about deploy finish');
task('discord:notify:success', function () {
get('send_message')(get('discord_success_text'));
})
->once()
->shallow()
->isPrivate();

desc('Notify Discord about deploy failure');
task('discord:notify:failure', function () {
get('send_message')(get('discord_failure_text'));
})
->once()
->shallow()
->isPrivate();

0 comments on commit d889eb4

Please sign in to comment.