PHP code example of oneduo / laravel-gitlab-webhook-client
1. Go to this page and download the library: Download oneduo/laravel-gitlab-webhook-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oneduo / laravel-gitlab-webhook-client example snippets
declare(strict_types=1);
return [
/*
|--------------------------------------------------------------------------
| Webhook route
|--------------------------------------------------------------------------
|
| Here you may choose to enable the default webhook route provided by
| the package. If you decide to disable this, you should manually register
| the route in your application and implement the event dispatching logic
| within your route.
|
| This registers the following route: POST /gitlab-webhook
|
| default: true
*/
'route_enabled' => true,
/*
|--------------------------------------------------------------------------
| Secret Token Middleware
|--------------------------------------------------------------------------
|
| You may set the value of the secret token defined in Gitlab.
| The package will validate all incoming requests against this given token,
| and reject all unauthorized requests.
|
| Set the value to NULL to disable the middleware.
|
| default: null
*/
'secret_token' => env('GITLAB_WEBHOOK_SECRET_TOKEN'),
];
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
MergeRequestEvent::class => [
MergeRequestEventListener::class,
],
];
}
declare(strict_types=1);
namespace App;
use App\Gitlab\Events\MergeRequestEvent;
class MergeRequestEventListener
{
public function handle(MergeRequestEvent $event): void
{
logger()->info('New merge request event received');
logger()->info($event->mergeRequest->title);
logger()->info('By: ' . $event->mergeRequest->last_commit->author->email);
}
}