diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm
index 9f257418..b8a35aaf 100644
--- a/src/lib/Hydra/Helper/CatalystUtils.pm
+++ b/src/lib/Hydra/Helper/CatalystUtils.pm
@@ -27,6 +27,7 @@ our @EXPORT = qw(
parseJobsetName
showJobName
showStatus
+ getResponsibleAuthors
);
@@ -250,4 +251,40 @@ sub showStatus {
}
+# Determine who broke/fixed the build.
+sub getResponsibleAuthors {
+ my ($build, $plugins) = @_;
+
+ my $prevBuild = getPreviousBuild($build);
+
+ my $nrCommits = 0;
+ my %authors;
+
+ if ($prevBuild) {
+ foreach my $curInput ($build->buildinputs_builds) {
+ next unless ($curInput->type eq "git" || $curInput->type eq "hg");
+ my $prevInput = $prevBuild->buildinputs_builds->find({ name => $curInput->name });
+ next unless defined $prevInput;
+
+ next if $curInput->type ne $prevInput->type;
+ next if $curInput->uri ne $prevInput->uri;
+ next if $curInput->revision eq $prevInput->revision;
+
+ my @commits;
+ foreach my $plugin (@{$plugins}) {
+ push @commits, @{$plugin->getCommits($curInput->type, $curInput->uri, $prevInput->revision, $curInput->revision)};
+ }
+
+ foreach my $commit (@commits) {
+ #print STDERR "$commit->{revision} by $commit->{author}\n";
+ $authors{$commit->{author}} = $commit->{email};
+ $nrCommits++;
+ }
+ }
+ }
+
+ return (\%authors, $nrCommits);
+}
+
+
1;
diff --git a/src/lib/Hydra/Plugin/HipChatNotification.pm b/src/lib/Hydra/Plugin/HipChatNotification.pm
index fb8f538b..59350ed3 100644
--- a/src/lib/Hydra/Plugin/HipChatNotification.pm
+++ b/src/lib/Hydra/Plugin/HipChatNotification.pm
@@ -40,31 +40,7 @@ sub buildFinished {
# Determine who broke/fixed the build.
my $prevBuild = getPreviousBuild($build);
- my $nrCommits = 0;
- my %authors;
-
- if ($prevBuild) {
- foreach my $curInput ($build->buildinputs_builds) {
- next unless ($curInput->type eq "git" || $curInput->type eq "hg");
- my $prevInput = $prevBuild->buildinputs_builds->find({ name => $curInput->name });
- next unless defined $prevInput;
-
- next if $curInput->type ne $prevInput->type;
- next if $curInput->uri ne $prevInput->uri;
- next if $curInput->revision eq $prevInput->revision;
-
- my @commits;
- foreach my $plugin (@{$self->{plugins}}) {
- push @commits, @{$plugin->getCommits($curInput->type, $curInput->uri, $prevInput->revision, $curInput->revision)};
- }
-
- foreach my $commit (@commits) {
- #print STDERR "$commit->{revision} by $commit->{author}\n";
- $authors{$commit->{author}} = $commit->{email};
- $nrCommits++;
- }
- }
- }
+ my ($authors, $nrCommits) = getResponsibleAuthors($build, $self->{plugins});
# Send a message to each room.
foreach my $roomId (keys %rooms) {
@@ -84,9 +60,9 @@ sub buildFinished {
$msg .= " (and ${\scalar @deps} others)" if scalar @deps > 0;
$msg .= ": " . showStatus($build) . "";
- if (scalar keys %authors > 0) {
+ if (scalar keys %{$authors} > 0) {
# FIXME: HTML escaping
- my @x = map { "$_" } (sort keys %authors);
+ my @x = map { "$_" } (sort keys %{$authors});
$msg .= ", likely due to ";
$msg .= "$nrCommits commits by " if $nrCommits > 1;
$msg .= join(" or ", scalar @x > 1 ? join(", ", @x[0..scalar @x - 2]) : (), $x[-1]);