From b03de925cbfb9eda2a5d1ed77836c4942f15550b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Jul 2015 15:17:35 +0200 Subject: [PATCH 1/2] Allow a jobset to be created from an evaluation Fixes #150. --- src/lib/Hydra/Controller/Jobset.pm | 4 ++-- src/lib/Hydra/Controller/JobsetEval.pm | 11 +++++++++ src/lib/Hydra/Controller/Project.pm | 2 -- src/root/edit-jobset.tt | 31 ++++++++++++++++++-------- src/root/jobset-eval.tt | 1 + 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index b9da12ee..529a456b 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -163,7 +163,7 @@ sub edit : Chained('jobsetChain') PathPart Args(0) { $c->stash->{template} = 'edit-jobset.tt'; $c->stash->{edit} = 1; - $c->stash->{clone} = defined $c->stash->{params}->{clone}; + $c->stash->{cloneJobset} = defined $c->stash->{params}->{cloneJobset}; $c->stash->{totalShares} = getTotalShares($c->model('DB')->schema); } @@ -269,7 +269,7 @@ sub clone : Chained('jobsetChain') PathPart('clone') Args(0) { requireProjectOwner($c, $c->stash->{project}); $c->stash->{template} = 'edit-jobset.tt'; - $c->stash->{clone} = 1; + $c->stash->{cloneJobset} = 1; $c->stash->{totalShares} = getTotalShares($c->model('DB')->schema); } diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index 65ae7fb0..c7ea4448 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -157,6 +157,17 @@ sub release : Chained('eval') PathPart('release') Args(0) { } +sub create_jobset : Chained('eval') PathPart('create-jobset') Args(0) { + my ($self, $c) = @_; + my $eval = $c->stash->{eval}; + + requireProjectOwner($c, $c->stash->{project}); + + $c->stash->{template} = 'edit-jobset.tt'; + $c->stash->{createFromEval} = 1; +} + + sub cancel : Chained('eval') PathPart('cancel') Args(0) { my ($self, $c) = @_; requireProjectOwner($c, $c->stash->{eval}->project); diff --git a/src/lib/Hydra/Controller/Project.pm b/src/lib/Hydra/Controller/Project.pm index 1fea107b..4cd577b1 100644 --- a/src/lib/Hydra/Controller/Project.pm +++ b/src/lib/Hydra/Controller/Project.pm @@ -113,7 +113,6 @@ sub create : Path('/create-project') { $c->stash->{template} = 'edit-project.tt'; $c->stash->{create} = 1; - $c->stash->{edit} = 1; } @@ -124,7 +123,6 @@ sub create_jobset : Chained('projectChain') PathPart('create-jobset') Args(0) { $c->stash->{template} = 'edit-jobset.tt'; $c->stash->{create} = 1; - $c->stash->{edit} = 1; $c->stash->{totalShares} = getTotalShares($c->model('DB')->schema); } diff --git a/src/root/edit-jobset.tt b/src/root/edit-jobset.tt index 0fc06abe..30b9a4c9 100644 --- a/src/root/edit-jobset.tt +++ b/src/root/edit-jobset.tt @@ -1,4 +1,8 @@ -[% WRAPPER layout.tt title=(create ? "Create jobset in project $project.name" : clone ? "Cloning jobset $project.name:$jobset.name" : "Editing jobset $project.name:$jobset.name") %] +[% WRAPPER layout.tt title= + (create ? "Creating jobset in project $project.name" : + createFromEval ? "Creating jobset from evaluation $eval.id of $project.name:$jobset.name" : + cloneJobset ? "Cloning jobset $project.name:$jobset.name" : + "Editing jobset $project.name:$jobset.name") %] [% PROCESS common.tt %] [% USE format %] @@ -11,16 +15,25 @@ input.name) %]/> - [% INCLUDE renderSelection curValue=input.type param="$baseName-type" options=inputTypes %] + [% INCLUDE renderSelection curValue=input.type param="$baseName-type" options=inputTypes edit=1 %] - [% alt = input.search_related('jobsetinputalts', {altnr => 0}) %] - alt.value, id => "$baseName-value", name => "$baseName-value") %]/> - [% IF input.jobsetinputalts_rs.count > 1 %] + [% IF createFromEval %] + [% value = (input.uri or input.value); IF input.revision; value = value _ " " _ input.revision; END; + warn = input.altnr != 0; + %] + [% ELSE %] + [% alt = input.search_related('jobsetinputalts', {altnr => 0}); + value = alt.value + warn = input.jobsetinputalts_rs.count > 1; + %] + [% END %] + [% IF warn %]
Warning: This input had more than one value. This is no longer supported. The additional values have been removed.
[% END %] + value, id => "$baseName-value", name => "$baseName-value") %]/> @@ -34,7 +47,7 @@ Input nameTypeValueNotify committers - [% FOREACH input IN jobset.jobsetinputs %] + [% inputs = createFromEval ? eval.jobsetevalinputs : jobset.jobsetinputs; FOREACH input IN inputs %] [% INCLUDE renderJobsetInput input=input baseName="input-$input.name" %] [% END %] @@ -71,7 +84,7 @@
- clone ? "" : jobset.name) %]/> + edit ? jobset.name : "") %]/>
@@ -139,7 +152,7 @@ [% INCLUDE renderJobsetInputs %]
- +
@@ -191,7 +204,7 @@ } } redirectJSON({ - [% IF create || clone %] + [% IF !edit %] url: "[% c.uri_for('/jobset' project.name '.new') %]", [% ELSE %] url: "[% c.uri_for('/jobset' project.name jobset.name) %]", diff --git a/src/root/jobset-eval.tt b/src/root/jobset-eval.tt index fb587fc8..48b44e87 100644 --- a/src/root/jobset-eval.tt +++ b/src/root/jobset-eval.tt @@ -46,6 +46,7 @@ c.uri_for(c.controller('JobsetEval').action_for('view'), From b85e9ef1cd54379a911c05c9eded9bc060dd796d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Jul 2015 15:55:34 +0200 Subject: [PATCH 2/2] Support using Git revisions as branch names --- src/lib/Hydra/Plugin/GitInput.pm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/Hydra/Plugin/GitInput.pm b/src/lib/Hydra/Plugin/GitInput.pm index 94dad9c3..66aaf625 100644 --- a/src/lib/Hydra/Plugin/GitInput.pm +++ b/src/lib/Hydra/Plugin/GitInput.pm @@ -13,6 +13,11 @@ sub supportedInputTypes { $inputTypes->{'git'} = 'Git checkout'; } +sub _isHash { + my ($rev) = @_; + return length($rev) == 40 && $rev =~ /^[0-9a-f]+$/; +} + # Clone or update a branch of a repository into our SCM cache. sub _cloneRepo { my ($self, $uri, $branch, $deepClone) = @_; @@ -24,15 +29,16 @@ sub _cloneRepo { my $res; if (! -d $clonePath) { # Clone everything and fetch the branch. - # TODO: Optimize the first clone by using "git init $clonePath" and "git remote add origin $uri". - $res = run(cmd => ["git", "clone", "--branch", $branch, $uri, $clonePath], timeout => 600); - die "error cloning git repo at `$uri':\n$res->{stderr}" if $res->{status}; + $res = run(cmd => ["git", "init", $clonePath]); + $res = run(cmd => ["git", "remote", "add", "origin", "--", $uri], dir => $clonePath) unless $res->{status}; + die "error creating git repo in `$clonePath':\n$res->{stderr}" if $res->{status}; } # This command forces the update of the local branch to be in the same as # the remote branch for whatever the repository state is. This command mirrors # only one branch of the remote repository. - $res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$branch"], dir => $clonePath, timeout => 600); + my $localBranch = _isHash($branch) ? "_hydra_tmp" : $branch; + $res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$localBranch"], dir => $clonePath, timeout => 600); $res = run(cmd => ["git", "fetch", "-fu", "origin"], dir => $clonePath, timeout => 600) if $res->{status}; die "error fetching latest change from git repo at `$uri':\n$res->{stderr}" if $res->{status}; @@ -78,7 +84,8 @@ sub fetchInput { my $sha256; my $storePath; - my $revision = grab(cmd => ["git", "rev-parse", "$branch"], dir => $clonePath, chomp => 1); + my $revision = _isHash($branch) ? $branch + : grab(cmd => ["git", "rev-parse", "$branch"], dir => $clonePath, chomp => 1); die "did not get a well-formated revision number of Git branch '$branch' at `$uri'" unless $revision =~ /^[0-9a-fA-F]+$/; @@ -104,8 +111,7 @@ sub fetchInput { if (defined $deepClone) { # Checked out code often wants to be able to run `git # describe', e.g., code that uses Gnulib's `git-version-gen' - # script. Thus, we leave `.git' in there. Same for - # Subversion (e.g., libgcrypt's build system uses that.) + # script. Thus, we leave `.git' in there. $ENV{"NIX_PREFETCH_GIT_LEAVE_DOT_GIT"} = "1"; # Ask for a "deep clone" to allow "git describe" and similar @@ -115,6 +121,7 @@ sub fetchInput { $ENV{"NIX_PREFETCH_GIT_DEEP_CLONE"} = "1"; } + # FIXME: Don't use nix-prefetch-git. ($sha256, $storePath) = split ' ', grab(cmd => ["nix-prefetch-git", $clonePath, $revision], chomp => 1); txn_do($self->{db}, sub {