From dd4e57fb0cbaf612e630b89b37d2edac89fb1668 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 11 Nov 2013 21:36:26 +0000 Subject: [PATCH] Allow passing a specific build as an input Fixes #62. --- src/lib/Hydra/Controller/Jobset.pm | 3 +++ src/lib/Hydra/Controller/Root.pm | 4 ++-- src/lib/Hydra/Helper/AddBuilds.pm | 24 +++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index fb82a584..55100b3f 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -175,14 +175,17 @@ sub nixExprPathFromParams { sub checkInputValue { my ($c, $name, $type, $value) = @_; $value = trim $value; + error($c, "The value ‘$value’ of input ‘$name’ is not a Boolean (‘true’ or ‘false’).") if $type eq "boolean" && !($value eq "true" || $value eq "false"); + error($c, "The value ‘$value’ of input ‘$name’ does not specify a Hydra evaluation. " . "It should be either the number of a specific evaluation, the name of " . "a jobset (given as :), or the name of a job (::).") if $type eq "eval" && $value !~ /^\d+$/ && $value !~ /^$projectNameRE:$jobsetNameRE$/ && $value !~ /^$projectNameRE:$jobsetNameRE:$jobNameRE$/; + return $value; } diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 0d7660a0..e60420b0 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -36,8 +36,8 @@ sub begin :Private { 'string' => 'String value', 'boolean' => 'Boolean', 'nix' => 'Nix expression', - 'build' => 'Build output', - 'sysbuild' => 'Build output (same system)', + 'build' => 'Previous Hydra build', + 'sysbuild' => 'Previous Hydra build (same system)', 'eval' => 'Previous Hydra evaluation' }; $_->supportedInputTypes($c->stash->{inputTypes}) foreach @{$c->hydra_plugins}; diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index 9e432473..f2ae6134 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -78,16 +78,22 @@ sub attrsToSQL { sub fetchInputBuild { my ($db, $project, $jobset, $name, $value) = @_; - my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value); - $projectName ||= $project->name; - $jobsetName ||= $jobset->name; + my $prevBuild; - # Pick the most recent successful build of the specified job. - (my $prevBuild) = $db->resultset('Builds')->search( - { finished => 1, project => $projectName, jobset => $jobsetName - , job => $jobName, buildStatus => 0 }, - { order_by => "me.id DESC", rows => 1 - , where => \ attrsToSQL($attrs, "me.id") }); + if ($value =~ /^\d+$/) { + $prevBuild = $db->resultset('Builds')->find({ id => int($value) }); + } else { + my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value); + $projectName ||= $project->name; + $jobsetName ||= $jobset->name; + + # Pick the most recent successful build of the specified job. + $prevBuild = $db->resultset('Builds')->search( + { finished => 1, project => $projectName, jobset => $jobsetName + , job => $jobName, buildStatus => 0 }, + { order_by => "me.id DESC", rows => 1 + , where => \ attrsToSQL($attrs, "me.id") })->single; + } return () if !defined $prevBuild || !isValidPath(getMainOutput($prevBuild)->path);