This repository has been archived by the owner on Apr 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
375c213
commit d889eb4
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |