From edbe531ccc0db0c292a9dd6d2343a04c90b64b82 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Thu, 21 Feb 2013 18:34:34 +0100
Subject: [PATCH] On build pages, provide a link to the build's first eval

---
 src/lib/Hydra/Controller/Build.pm | 5 +++++
 src/lib/Hydra/Schema/Builds.pm    | 8 ++++++++
 src/root/build.tt                 | 6 ++++++
 3 files changed, 19 insertions(+)

diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm
index bb6a47ce..05edea1d 100644
--- a/src/lib/Hydra/Controller/Build.pm
+++ b/src/lib/Hydra/Controller/Build.pm
@@ -91,6 +91,11 @@ sub view_build : Chained('build') PathPart('') Args(0) {
         ];
     }
 
+    # Get the first eval of which this build was a part.
+    ($c->stash->{eval}) = $c->stash->{build}->jobsetevals->search(
+        { hasnewbuilds => 1},
+        { limit => 1, order_by => ["id"] });
+
     my $maxRelated = 100;
     my $r = $c->model('DB::Builds')->search(
         { eval => { -in => $build->jobsetevalmembers->search({}, {rows => 1})->get_column('eval')->as_query } },
diff --git a/src/lib/Hydra/Schema/Builds.pm b/src/lib/Hydra/Schema/Builds.pm
index 9b0905a7..1cd0243e 100644
--- a/src/lib/Hydra/Schema/Builds.pm
+++ b/src/lib/Hydra/Schema/Builds.pm
@@ -482,6 +482,12 @@ __PACKAGE__->has_many(
   { "foreign.build" => "self.id" },
 );
 
+__PACKAGE__->has_many(
+  "evals",
+  "Hydra::Schema::BuildInputs",
+  { "foreign.build" => "self.id" },
+);
+
 #__PACKAGE__->has_one(
 #  "actualBuildStep",
 #  "Hydra::Schema::BuildSteps",
@@ -490,6 +496,8 @@ __PACKAGE__->has_many(
 #  },
 #);
 
+__PACKAGE__->many_to_many("jobsetevals", "jobsetevalmembers", "eval");
+
 sub makeSource {
     my ($name, $query) = @_;
     my $source = __PACKAGE__->result_source_instance();
diff --git a/src/root/build.tt b/src/root/build.tt
index 2c800f03..c2b8b2f8 100644
--- a/src/root/build.tt
+++ b/src/root/build.tt
@@ -97,6 +97,12 @@
               <th>System:</th>
               <td><tt>[% build.system %]</tt></td>
             </tr>
+            [% IF eval %]
+              <tr>
+                <th>Part of:</th>
+                <td><a href="[% c.uri_for(c.controller('JobsetEval').action_for('view'), [eval.id]) %]">evaluation [% eval.id %]</a></td>
+              </tr>
+            [% END %]
             [% IF build.releasename %]
               <tr>
                 <th>Release name:</th>