2017 © Pedro Peláez
 

library webhook-manager

Easily associate one or more actions with a specific repository event using webhooks

image

gnello/webhook-manager

Easily associate one or more actions with a specific repository event using webhooks

  • Monday, September 25, 2017
  • by gnello
  • Repository
  • 1 Watchers
  • 1 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 8 % Grown

The README.md

WebhookManager

Build Status Latest Stable Version Scrutinizer Code Quality [![Total Downloads][11]][12], (*1)

Bitbucket Github ![TravisCI][10], (*2)

WebhookManager easily associates one or more actions with a specific repository event using webhooks.
Services supported: Bitbucket, Github, TravisCI and every custom service., (*3)

Installation

It's highly recommended to use composer to install WebhookManager:, (*4)

composer require gnello/webhook-manager

Read more about how to install and use Composer on your local machine here., (*5)

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:, (*6)

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

On custom service

This is up to you!, (*7)

Usage

WebhookManager usage is very simple:, (*8)

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., (*9)

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

  • luca@gnello.com

The Versions

25/09 2017

dev-master

9999999-dev https://github.com/gnello/webhook-manager

Easily associate one or more actions with a specific repository event using webhooks

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Luca Agnello

github webhook bitbucket travisci

24/09 2017

1.2.0

1.2.0.0 https://github.com/gnello/webhook-manager

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Luca Agnello

github webhook bitbucket

24/09 2017

1.1.0

1.1.0.0 https://github.com/gnello/webhook-manager

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Luca Agnello

github webhook bitbucket

24/09 2017

1.0.2

1.0.2.0 https://github.com/gnello/webhook-manager

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Luca Agnello

github webhook bitbucket

24/09 2017

1.0.1

1.0.1.0 https://github.com/gnello/webhook-manager

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Luca Agnello

github webhook bitbucket

24/09 2017

1.0.0

1.0.0.0 https://github.com/gnello/webhook-manager

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Luca Agnello

github webhook bitbucket