Skip to content

This repository easily manage webhooks launched by bitbucket, github, or any other server

License

Notifications You must be signed in to change notification settings

gnello/webhook-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebhookManager

Build Status Latest Stable Version Scrutinizer Code Quality Total Downloads

Bitbucket Github TravisCI

WebhookManager easily associates 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

WebhookManager usage 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, BitbucketService::BUILD_STATUS_UPDATED], 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 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();

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

About

This repository easily manage webhooks launched by bitbucket, github, or any other server

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages