WebhookManager easily associates one or more actions with a specific repository event using webhooks.
Services supported: Bitbucket, Github, TravisCI and every custom service.
It's highly recommended to use composer to install WebhookManager:
composer require gnello/webhook-manager
Read more about how to install and use Composer on your local machine here.
- Go to the settings of your repository
- Click on "Webhooks" under "Workflow"
- Click on "Add webhook"
- Enter the url of WebhookManager configured on your server (es. https://mysite.com/webhooks)
- Set the triggers
- Save!
- Go to the settings of your repository
- Click on "Webhooks" under "Options"
- Click on "Add webhook"
- Enter the url of WebhookManager configured on your server (es. https://mysite.com/webhooks)
- Set the content type on
application/json
- Set the events
- Save!
Add this in your .travis.yml
file:
notifications:
webhooks: url of WebhookManager configured on your server (es. https://mysite.com/webhooks)
This is up to you!
WebhookManager usage is very simple:
require '../vendor/autoload.php';
use \Gnello\WebhookManager\App;
use \Gnello\WebhookManager\Services\BitbucketService;
$webhookManager = new App();
//Action on build passed
$webhookManager->add([BitbucketService::BUILD_STATUS_CREATED, BitbucketService::BUILD_STATUS_UPDATED], function(BitbucketService $service) {
$payload = $service->getPayload();
if ($payload['commit_status']['state'] == 'SUCCESSFUL') {
//do some stuff
}
});
$webhookManager->listen();
require '../vendor/autoload.php';
use \Gnello\WebhookManager\App;
use \Gnello\WebhookManager\Services\GithubService;
$webhookManager = new App(['service' => GithubService::class]);
//Action on push event
$webhookManager->add(GithubService::PUSH, function(GithubService $service) {
$payload = $service->getPayload();
//do some stuff
});
$webhookManager->listen();
require '../vendor/autoload.php';
use \Gnello\WebhookManager\App;
use \Gnello\WebhookManager\Services\TravisCIService;
$webhookManager = new App(['service' => TravisCIService::class]);
//Action on build passed
$webhookManager->add(TravisCIService::PUSH, function(TravisCIService $service) {
$payload = $service->getPayload();
if ($payload['state'] === 'passed') {
//do some stuff
}
});
$webhookManager->listen();
To use a custom service, you should create a class that implements the \Gnello\WebhookManager\Services\ServiceInterface
interface
and then register it on WebhookManager. In WebhookManager options, you should specify that you want to use a custom service.
require '../vendor/autoload.php';
use \Gnello\WebhookManager\App;
$webhookManager = new App(['service' => \YourCustomService::class]);
//Action on custom event
$webhookManager->add('custom_event', function(\YourCustomService $service) {
$payload = $service->getPayload();
//do some stuff
});
$webhookManager->add('another_event', function(\YourCustomService $service) {
//do some stuff
});
$webhookManager->listen();
- Bitbucket is the default service, but you can change it as follows:
//github
$webhookManager = new \Gnello\WebhookManager\App([
'service' => \Gnello\WebhookManager\Services\GithubService::class
]);
//travis ci
$webhookManager = new \Gnello\WebhookManager\App([
'service' => \Gnello\WebhookManager\Services\TravisCIService::class
]);
//custom service
$webhookManager = new \Gnello\WebhookManager\App([
'service' => \Gnello\WebhookManager\Services\YourCustomService::class
]);
- The json_decode of Bitbucket and Github services is set to convert the returned objects into associative arrays. You can change this behavior in this way:
$webhookManager = new \Gnello\WebhookManager\App([
'json_decode_assoc' => false
]);