fatindeed / gitlab-webhook-handler
GitLab Webhook Handler
1.0.0
2019-06-18 01:24 UTC
Requires
- php: >=7.1
- psr/log: ^1.1
- queue-interop/queue-interop: ^0.8
- timo-reymann/gitlab-webhook-lib: ^1.2
Requires (Dev)
- phpunit/phpunit: ^7.0 || ^8.0
Suggests
- ext-pcntl: Process Control extension
- enqueue/fs: Enqueue Filesystem based transport
- monolog/monolog: Sends your logs to files, sockets, inboxes, databases and various web services
- vlucas/phpdotenv: Loads environment variables from `.env`
This package is auto-updated.
Last update: 2024-10-18 13:07:09 UTC
README
Install
composer require fatindeed/gitlab-webhook-handler
Developer Guide
TODO
User Guide
Create Event
-
With Secret token
use TimoReymann\GitlabWebhookLibrary\Core\Webhook; use TimoReymann\GitlabWebhookLibrary\Token\SecretToken; $hook = new Webhook(new SecretToken('mySuperSecretToken')); $event = $hook->parse();
-
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
-
Install a Queue Interop compatible transport, for example
$ composer require enqueue/fs
More Queue Interop compatible transport implementations can be found here.
-
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
-
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...