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;