fatindeed/gitlab-webhook-handler

1.0.0 2019-06-18 01:24 UTC

This package is auto-updated.

Last update: 2024-11-18 13:22:25 UTC


README

PHP Version Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Install

composer require fatindeed/gitlab-webhook-handler

Developer Guide

TODO

User Guide

Create Event

  1. With Secret token

    use TimoReymann\GitlabWebhookLibrary\Core\Webhook;
    use TimoReymann\GitlabWebhookLibrary\Token\SecretToken;
    
    $hook = new Webhook(new SecretToken('mySuperSecretToken'));
    $event = $hook->parse();
  2. Without Secret token

    use TimoReymann\GitlabWebhookLibrary\Event\EventType;
    
    $eventType = new EventType;
    $event = $eventType->getEventDataFromBody(file_get_contents('php://input'));

Sync Handler Example

use Fatindeed\GitlabWebhookHandler\EventSubject;

$object = new YourWebhookHandler; // Replace with you webhook handler

$subject = new EventSubject;
$subject->attach($object);
$subject->dispatch($event); // Event created above

Async Handler Example

  1. Install a Queue Interop compatible transport, for example

    $ composer require enqueue/fs

    More Queue Interop compatible transport implementations can be found here.

  2. Webhook receiver (Web Server)

    use Enqueue\Fs\FsConnectionFactory;
    use Fatindeed\GitlabWebhookHandler\EventSubject;
    
    $context = (new FsConnectionFactory)->createContext(); // Create a filesystem queue
    
    $subject = new EventSubject;
    $subject->dispatch($event, $context); // Event created above
  3. Daemon process (Run in background)

    use Enqueue\Fs\FsConnectionFactory;
    use Fatindeed\GitlabWebhookHandler\EventSubject;
    
    $object = new YourWebhookHandler; // Replace with you webhook handler
    $context = (new FsConnectionFactory)->createContext(); // Create a filesystem queue
    
    $subject = new EventSubject;
    $subject->signalInstall(SIGTERM, [$subject, 'terminate']); // Alternative
    $subject->attach($object);
    $subject->run($context);

With Monolog

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('application');
$logger->pushHandler(new StreamHandler(STDOUT, Logger::INFO));
$subject = new EventSubject($logger);
# code...