Download the PHP package iwink/gitlab-webhook-bundle without Composer
On this page you can find all versions of the php package iwink/gitlab-webhook-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package gitlab-webhook-bundle
GitLab Webhook Bundle
Symfony bundle to process GitLab webhooks.
Installation
To use this bundle, install it using Composer: composer require iwink/gitlab-webhook-bundle
. If
your project uses Symfony Flex, you are done. If not, make sure to enable the bundle
in your project's config/bundles.php
.
Usage
To mark a controller as a GitLab webhook, you can use the @Webhook(event="event")
annotation above your controller and
define a Iwink\GitLabWebhookBundle\Event\WebhookEvent
argument in your method:
The example above annotates the pipeline
method as a webhook which receives a
Pipeline Hook
event by using
the @Webhook("pipeline")
annotation. The event is injected into the method's $event
argument. The injection is based
on the typehint (PipelineEvent
) of the argument, the argument's name doesn't matter. Because GitLab expects a response
as soon as possible, the
expensive part of the webhook is scheduled and executed after a response has been sent by the
Iwink\GitLabWebhookBundle\Scheduler::schedule()
method.
Secured webhooks
GitLab has the option to secure a webhook with a secret token. You can define these secret tokens in a webhook annotation:
The received Pipeline Hook
request should now contain the secret token (provided by the X-GitLab-Token
header), otherwise the request fails. The tokens
should be defined as an array because it's possible to define multiple tokens for the same annotation since multiple
GitLab projects might trigger the same webhook. The tokens can also be defined as a
configuration parameter using the
%parameter.name%
format: @Webhook("pipeline", tokens={"%gitlab.secret_token%"})
. Since parameters can contain
environment variables,
configuring the secrets is very flexible.
Caveat
Because Symfony caches the annotations, and the file defining the annotation is not changed when updating a parameter,
you should manually clear the cache after changing a secret parameter's value. This will only ever happen in the dev
environment because in the prod
environment the container is always cached (everytime your code changes, you will need
to clear the cache).
Multiple webhooks
It's possible to register multiple webhooks to a single controller by using multiple @Webhook
annotations:
The injected $event
is now either a Iwink\GitLabWebhookBundle\Event\PushEvent
or a
Iwink\GitLabWebhookBundle\Event\MergeRequestEvent
. Notice the difference between the 2 @Webhook
annotations, both
the short (@Webhook("push")
) and the long (@Webhook(event="merge request")
) syntax give the same result so it
doesn't matter which syntax you use.
Supported webhooks
The following webhooks are supported:
- comment (
Iwink\GitLabWebhookBundle\Event\CommentEvent
) - deployment (
Iwink\GitLabWebhookBundle\Event\DeploymentEvent
) - feature flag (
Iwink\GitLabWebhookBundle\Event\FeatureFlagEvent
) - issue (
Iwink\GitLabWebhookBundle\Event\IssueEvent
) - job (
Iwink\GitLabWebhookBundle\Event\JobEvent
) - merge request (
Iwink\GitLabWebhookBundle\Event\MergeRequestEvent
) - pipeline (
Iwink\GitLabWebhookBundle\Event\PipelineEvent
) - push (
Iwink\GitLabWebhookBundle\Event\PushEvent
) - release (
Iwink\GitLabWebhookBundle\Event\ReleaseEvent
) - system (
Iwink\GitLabWebhookBundle\Event\SystemEvent
) - tag (
Iwink\GitLabWebhookBundle\Event\TagEvent
) - wiki page (
Iwink\GitLabWebhookBundle\Event\WikiPageEvent
)
All versions of gitlab-webhook-bundle with dependencies
ext-json Version *
doctrine/annotations Version ^1.11|^2.0
symfony/config Version ^5.0|^6.0
symfony/dependency-injection Version ^5.0|^6.0
symfony/http-kernel Version ^5.0|^6.0
symfony/yaml Version ^5.0|^6.0