Skip to content

Instantly share code, notes, and snippets.

@toke
Created February 9, 2012 17:18
Show Gist options
  • Save toke/1781347 to your computer and use it in GitHub Desktop.
Save toke/1781347 to your computer and use it in GitHub Desktop.
Dancer github webhook receiver. More Info on: http://toke.de/blog/2012/02/09/how-i-post/ now has an own repo https://github.com/toke/dancing-github-webhooks
package receivehook;
use Dancer ':syntax';
our $VERSION = '0.3';
# Configuration for different projects
my $config = {
"PROJECTNAME" => {
run => "/home/user/bin/updateblog.sh",
},
};
prefix '/notify';
get '/*' => sub {
header 'Allow' => 'POST';
status '405';
"Not for you\n";
};
post '/:project' => sub {
if (not defined $config->{params->{project}}) {
status 'not_found';
return "No such project: ".params->{project}."\n";
}
my $payload = params->{'payload'};
if (not defined $payload) {
status '415';
return "I need a payload\n";
}
# Read the configuration for that repo
my $repo_config = $config->{$repo->{name}};
if (defined $repo_config && defined $repo_config->{run}) {
eval {
system $repo_config->{run};
};
}
return "OK";
};
true;
@toke
Copy link
Author

toke commented Apr 23, 2012

Can now be found in an own repository: https://github.com/toke/dancing-github-webhooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment