diff --git a/src/lib/Hydra/Controller/API.pm b/src/lib/Hydra/Controller/API.pm index 580f6957..664cdd4d 100644 --- a/src/lib/Hydra/Controller/API.pm +++ b/src/lib/Hydra/Controller/API.pm @@ -4,10 +4,12 @@ use strict; use warnings; use base 'Catalyst::Controller'; use Hydra::Helper::Nix; +use Hydra::Helper::AddBuilds; use Hydra::Helper::CatalystUtils; use Hydra::Controller::Project; use JSON::Any; use DateTime; +use Digest::SHA qw(sha256_hex); sub api : Chained('/') PathPart('api') CaptureArgs(0) { my ($self, $c) = @_; @@ -206,4 +208,30 @@ sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) { $c->forward('Hydra::View::Plain'); } +sub scmdiff : Chained('api') PathPart('scmdiff') Args(0) { + my ($self, $c) = @_; + + my $uri = $c->request->params->{uri} ; + my $type = $c->request->params->{type} ; + my $branch = $c->request->params->{branch} ; + my $rev1 = $c->request->params->{rev1} ; + my $rev2 = $c->request->params->{rev2} ; + + my $diff = ""; + if($type eq "hg") { + my $clonePath = scmPath . "/" . sha256_hex($uri); + die if ! -d $clonePath; + $diff .= `(cd $clonePath ; hg log -r $rev1:$rev2)`; + $diff .= `(cd $clonePath ; hg diff -r $rev1:$rev2)`; + } elsif ($type eq "git") { + my $clonePath = scmPath . "/" . sha256_hex($uri.$branch); + die if ! -d $clonePath; + $diff .= `(cd $clonePath ; git log $rev1..$rev2)`; + $diff .= `(cd $clonePath ; git diff $rev1..$rev2)`; + } + + $c->stash->{'plain'} = { data => (scalar $diff) || " " }; + $c->forward('Hydra::View::Plain'); +} + 1; diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 1b4c001d..d5977b36 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -150,6 +150,7 @@ sub robots_txt : Path('robots.txt') { , uri_for('Root', 'nar', [], "*") , uri_for('Root', 'status', []) , uri_for('Root', 'all', []) + , uri_for('API', 'scmdiff', []) , uri_for('Project', 'all', ["*"]) , channelUris('Root', ["*"]) , channelUris('Project', ["*", "*"]) diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index 2a497ab6..74ebf8fc 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -12,7 +12,7 @@ use File::stat; use File::Path; our @ISA = qw(Exporter); -our @EXPORT = qw(fetchInput evalJobs checkBuild inputsToArgs captureStdoutStderr getReleaseName getBuildLog addBuildProducts restartBuild); +our @EXPORT = qw(fetchInput evalJobs checkBuild inputsToArgs captureStdoutStderr getReleaseName getBuildLog addBuildProducts restartBuild scmPath); sub scmPath { return getHydraPath . "/scm" ; diff --git a/src/root/common.tt b/src/root/common.tt index 5672d782..d4f7e183 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -308,7 +308,14 @@ [% END %] [% END %] [% IF nouri %] - [% contents %] + [% res = bi1.uri.split(' ') %] + [% url = res.0 %] + [% branch = res.1 %] + [% IF bi1.type == "hg" || bi1.type == "git" %] + [% contents %] + [% ELSE %] + [% contents %] + [% END %] [% END %] [% END %]