This repository allows you to easily manage webhooks launched by bitbucket, github, or any other server
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
logos
src
tests
.travis.yml
LICENSE
README.md
_config.yml
composer.json
composer.lock

README.md

WebhookManager

Build Status Latest Stable Version Scrutinizer Code Quality

Bitbucket Github TravisCI

WebhookManager allows you to easily associate one or more actions with a specific repository event using webhooks.
Services supported: Bitbucket, Github, TravisCI and every custom service.

Installation

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.

Configuration

On Bitbucket

  • 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!

On Github

  • 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!

On TravisCI

Add this in your .travis.yml file:

notifications:
  webhooks: url of WebhookManager configured on your server (es. https://mysite.com/webhooks)

On custom service

This is up to you!

Usage

Using WebhookManager is very simple:

Bitbucket

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, function(BitbucketService $service) {
    $payload = $service->getPayload();

    if ($payload['commit_status']['state'] == 'SUCCESSFUL') {
        //do some stuff
    }
});

$webhookManager->listen();

Github

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();

TravisCI

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();

Custom service

To use a custom service, you must create a class that implements the \Gnello\WebhookManager\Services\ServiceInterface interface and then register it on WebhookManager. In WebhookManager options, you must 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();

Options

  • 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
]);

Contact