From 90eedcf2567b4125197095b1f1310fba783c10e3 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Wed, 7 Aug 2013 08:53:32 +0000 Subject: [PATCH] HipChat notification: add support for Mercurial inputs for determining who might have broken the build. --- src/lib/Hydra/Plugin/HipChatNotification.pm | 2 +- src/lib/Hydra/Plugin/MercurialInput.pm | 48 +++++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/lib/Hydra/Plugin/HipChatNotification.pm b/src/lib/Hydra/Plugin/HipChatNotification.pm index 5ca61378..91e5464f 100644 --- a/src/lib/Hydra/Plugin/HipChatNotification.pm +++ b/src/lib/Hydra/Plugin/HipChatNotification.pm @@ -45,7 +45,7 @@ sub buildFinished { if ($prevBuild) { foreach my $curInput ($build->buildinputs_builds) { - next unless $curInput->type eq "git"; + next unless ($curInput->type eq "git" || $curInput->type eq "hg"); my $prevInput = $prevBuild->buildinputs_builds->find({ name => $curInput->name }); next unless defined $prevInput; diff --git a/src/lib/Hydra/Plugin/MercurialInput.pm b/src/lib/Hydra/Plugin/MercurialInput.pm index 02ea0ccc..160be7b4 100644 --- a/src/lib/Hydra/Plugin/MercurialInput.pm +++ b/src/lib/Hydra/Plugin/MercurialInput.pm @@ -12,21 +12,33 @@ sub supportedInputTypes { $inputTypes->{'hg'} = 'Mercurial checkout'; } +sub _parseValue { + my ($value) = @_; + (my $uri, my $id) = split ' ', $value; + $id = defined $id ? $id : "default"; + return ($uri, $id); +} + +sub _clonePath { + my ($uri) = @_; + my $cacheDir = getSCMCacheDir . "/hg"; + mkpath($cacheDir); + return $cacheDir . "/" . sha256_hex($uri); +} + sub fetchInput { my ($self, $type, $name, $value) = @_; return undef if $type ne "hg"; - (my $uri, my $id) = split ' ', $value; + (my $uri, my $id) = _parseValue($value); $id = defined $id ? $id : "default"; # init local hg clone my $stdout = ""; my $stderr = ""; - my $cacheDir = getSCMCacheDir . "/hg"; - mkpath($cacheDir); - my $clonePath = $cacheDir . "/" . sha256_hex($uri); + my $clonePath = _clonePath($uri); if (! -d $clonePath) { (my $res, $stdout, $stderr) = captureStdoutStderr(600, @@ -85,4 +97,32 @@ sub fetchInput { }; } +sub getCommits { + my ($self, $type, $value, $rev1, $rev2) = @_; + return [] if $type ne "hg"; + + return [] unless $rev1 =~ /^[0-9a-f]+$/; + return [] unless $rev2 =~ /^[0-9a-f]+$/; + + my ($uri, $id) = _parseValue($value); + + my $clonePath = _clonePath($uri); + chdir $clonePath or die $!; + + my $out; + IPC::Run::run(["hg", "log", "--template", "{node|short}\t{author|person}\t{author|email}\n", "-r", "$rev1:$rev2", $clonePath], \undef, \$out) + or die "cannot get mercurial logs: $?"; + + my $res = []; + foreach my $line (split /\n/, $out) { + if ($line ne "") { + my ($revision, $author, $email) = split "\t", $line; + push @$res, { revision => $revision, author => $author, email => $email }; + } + } + + return $res; +} + + 1;