From f501648cd2c24e940b564861524c21b3b14fc15c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 26 Feb 2013 01:14:50 +0100 Subject: [PATCH] Add simpler push support for GitHub You can use the URL http:///api/push-github as GitHub's WebHook URL. Hydra will automatically trigger an evaluation of all affected jobsets. --- src/lib/Hydra/Controller/API.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/Hydra/Controller/API.pm b/src/lib/Hydra/Controller/API.pm index de91ffee..dfbe8b2e 100644 --- a/src/lib/Hydra/Controller/API.pm +++ b/src/lib/Hydra/Controller/API.pm @@ -8,6 +8,7 @@ use Hydra::Helper::Nix; use Hydra::Helper::AddBuilds; use Hydra::Helper::CatalystUtils; use Hydra::Controller::Project; +use JSON; use JSON::Any; use DateTime; use Digest::SHA qw(sha256_hex); @@ -321,4 +322,25 @@ sub push : Chained('api') PathPart('push') Args(0) { } +sub push_github : Chained('api') PathPart('push-github') Args(0) { + my ($self, $c) = @_; + + $c->{stash}->{json}->{jobsetsTriggered} = []; + + my $in = decode_json $c->req->body_params->{payload}; + my $owner = $in->{repository}->{owner}->{name} or die; + my $repo = $in->{repository}->{name} or die; + print STDERR "got push from GitHub repository $owner/$repo\n"; + + triggerJobset($self, $c, $_) foreach $c->model('DB::Jobsets')->search( + { 'project.enabled' => 1, 'me.enabled' => 1 }, + { join => 'project' + , where => \ [ 'exists (select 1 from JobsetInputAlts where project = me.project and jobset = me.name and value like ?)', [ 'value', "%github.com%/$owner/$repo.git%" ] ] + }); + + $c->forward('View::JSON'); +} + + + 1;