hydra: when no external url is given for diff's of git/hg input, revert to a diff done on a local available clone

This commit is contained in:
Rob Vermaas 2011-08-25 14:50:31 +00:00
parent c51af99ecf
commit 5d3f5f9fca
4 changed files with 38 additions and 2 deletions

View file

@ -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;

View file

@ -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', ["*", "*"])

View file

@ -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" ;

View file

@ -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" %]
<a target="_new" href="/api/scmdiff?uri=[% url %]&rev1=[% bi1.revision %]&rev2=[% bi2.revision %]&type=[% bi1.type %]&branch=[% branch %]">[% contents %]</a>
[% ELSE %]
[% contents %]
[% END %]
[% END %]
[% END %]