Plack::App::GitHub::WebHook - GitHub WebHook receiver as Plack application
version 0.4
use Plack::App::GitHub::WebHook; Plack::App::GitHub::WebHook->new( hook => sub { my $payload = shift; ... } )->to_app;
If multiple hooks are provided, they get called one by one until a hook returns a false value.
use Plack::App::GitHub::WebHook; use IPC::Run3; Plack::App::GitHub::WebHook->new( hook => [ sub { $_[0]->{repository}{name} eq 'foo' }, # filter sub { my ($payload) = @_; ... }, # some action sub { run3 \@cmd ... }, # some more action ] )->to_app;
By default access is restricted to known GitHub WebHook IPs.
Plack::App::GitHub::WebHook->new( hook => sub { ... }, access => [ allow => "204.232.175.64/27", allow => "192.30.252.0/22", deny => 'all' ] )->to_app; # this is equivalent to use Plack::Builder; builder { mount 'notify' => builder { enable 'Access', rules => [ allow => "204.232.175.64/27", allow => "192.30.252.0/22", deny => 'all' ] Plack::App::GitHub::WebHook->new( hook => sub { ... } ); } };
This PSGI application receives HTTP POST requests with body parameter payload set to a JSON object. The default use case is to receive GitHub WebHooks.
payload
The response of a HTTP request to this application is one of:
If access was not granted (for instance because it did not origin from GitHub).
If the request was no HTTP POST.
If the payload was no well-formed JSON. A later version of this module may add further validation.
Otherwise, if the hook was called and returned a true value.
Otherwise, if the hook was called and returned a false value.
This module requires at least Perl 5.10.
A code reference or an array reference of code references with multiple tasks. Each task gets passed the encoded payload. If the task returns a true value, next the task is called or HTTP status code 200 is returned. Information can be passed from one task to the next by modifying the payload.
If a task fails or no task was given, HTTP status code 202 is returned immediately. This mechanism can be used for conditional hooks or to detect hooks that were called successfully but failed to execute for some reason.
Access restrictions, as passed to Plack::Middleware::Access. See SYNOPSIS for the default value. A recent list of official GitHub WebHook IPs is vailable at https://api.github.com/meta. One should only set the access value on instantiation, or manually call prepare_app after modification.
prepare_app
WWW::GitHub::PostReceiveHook uses Web::Simple to receive GitHub web hooks. Net::GitHub and Pithub provide access to GitHub APIs.
Jakob Voß
This software is copyright (c) 2014 by Jakob Voß.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::App::GitHub::WebHook, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::App::GitHub::WebHook
CPAN shell
perl -MCPAN -e shell install Plack::App::GitHub::WebHook
For more information on module installation, please visit the detailed CPAN module installation guide.