diff --git a/release.nix b/release.nix index 372e31f8..b20435f8 100644 --- a/release.nix +++ b/release.nix @@ -37,8 +37,9 @@ in rec { build = genAttrs' (system: + let pkgs = import nixpkgs { inherit system; }; in - with import nixpkgs { inherit system; }; + with pkgs; let diff --git a/src/hydra-eval-jobs/hydra-eval-jobs.cc b/src/hydra-eval-jobs/hydra-eval-jobs.cc index 2be3dd80..ae737527 100644 --- a/src/hydra-eval-jobs/hydra-eval-jobs.cc +++ b/src/hydra-eval-jobs/hydra-eval-jobs.cc @@ -29,7 +29,7 @@ static void findJobs(EvalState & state, JSONObject & top, Bindings & autoArgs, Value & v, const string & attrPath); -static string queryMetaStrings(EvalState & state, DrvInfo & drv, const string & name) +static string queryMetaStrings(EvalState & state, DrvInfo & drv, const string & name, const string & subAttribute) { Strings res; std::function rec; @@ -42,7 +42,7 @@ static string queryMetaStrings(EvalState & state, DrvInfo & drv, const string & for (unsigned int n = 0; n < v.listSize(); ++n) rec(*v.listElems()[n]); else if (v.type == tAttrs) { - auto a = v.attrs->find(state.symbols.create("shortName")); + auto a = v.attrs->find(state.symbols.create(subAttribute)); if (a != v.attrs->end()) res.push_back(state.forceString(*a->value)); } @@ -117,9 +117,9 @@ static void findJobsWrapped(EvalState & state, JSONObject & top, res.attr("system", drv->querySystem()); res.attr("drvPath", drvPath = drv->queryDrvPath()); res.attr("description", drv->queryMetaString("description")); - res.attr("license", queryMetaStrings(state, *drv, "license")); + res.attr("license", queryMetaStrings(state, *drv, "license", "shortName")); res.attr("homepage", drv->queryMetaString("homepage")); - res.attr("maintainers", queryMetaStrings(state, *drv, "maintainers")); + res.attr("maintainers", queryMetaStrings(state, *drv, "maintainers", "email")); res.attr("schedulingPriority", drv->queryMetaInt("schedulingPriority", 100)); res.attr("timeout", drv->queryMetaInt("timeout", 36000)); res.attr("maxSilent", drv->queryMetaInt("maxSilent", 7200)); diff --git a/src/hydra-queue-runner/build-remote.cc b/src/hydra-queue-runner/build-remote.cc index dccc4469..69c430eb 100644 --- a/src/hydra-queue-runner/build-remote.cc +++ b/src/hydra-queue-runner/build-remote.cc @@ -29,6 +29,7 @@ static void append(Strings & dst, const Strings & src) static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Child & child) { + string pgmName; Pipe to, from; to.create(); from.create(); @@ -47,9 +48,12 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil throw SysError("cannot dup stderr"); Strings argv; - if (machine->sshName == "localhost") + if (machine->sshName == "localhost") { + pgmName = "nix-store"; argv = {"nix-store", "--serve", "--write"}; + } else { + pgmName = "ssh"; argv = {"ssh", machine->sshName}; if (machine->sshKey != "") append(argv, {"-i", machine->sshKey}); if (machine->sshPublicHostKey != "") { @@ -66,7 +70,7 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil execvp(argv.front().c_str(), (char * *) stringsToCharPtrs(argv).data()); // FIXME: remove cast - throw SysError("cannot start ssh"); + throw SysError("cannot start %s", pgmName); }); to.readSide = -1; diff --git a/src/hydra-queue-runner/dispatcher.cc b/src/hydra-queue-runner/dispatcher.cc index 531c6b46..068d5c57 100644 --- a/src/hydra-queue-runner/dispatcher.cc +++ b/src/hydra-queue-runner/dispatcher.cc @@ -152,7 +152,7 @@ system_time State::doDispatch() establish priority between builds in the same jobset, but here it's used between steps in different jobsets if they happen to have the same lowest used scheduling share. But - that's not every likely. + that's not very likely. - The lowest ID of the builds depending on the step; i.e. older builds take priority over new ones. diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 146c37a4..a486091f 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -237,7 +237,13 @@ sub end : ActionClass('RenderView') { elsif (scalar @{$c->error}) { $c->stash->{resource} = { error => join "\n", @{$c->error} }; - $c->stash->{template} = 'error.tt'; + if ($c->stash->{lazy}) { + $c->response->headers->header('X-Hydra-Lazy', 'Yes'); + $c->stash->{template} = 'lazy_error.tt'; + } + else { + $c->stash->{template} = 'error.tt'; + } $c->stash->{errors} = $c->error; $c->response->status(500) if $c->response->status == 200; if ($c->response->status >= 300) { diff --git a/src/lib/Hydra/Controller/User.pm b/src/lib/Hydra/Controller/User.pm index e9953a83..cad19d78 100644 --- a/src/lib/Hydra/Controller/User.pm +++ b/src/lib/Hydra/Controller/User.pm @@ -349,9 +349,10 @@ sub dashboard :Chained('dashboard_base') :PathPart('') :Args(0) { sub my_jobs_tab :Chained('dashboard_base') :PathPart('my-jobs-tab') :Args(0) { my ($self, $c) = @_; + $c->stash->{lazy} = 1; $c->stash->{template} = 'dashboard-my-jobs-tab.tt'; - die unless $c->stash->{user}->emailaddress; + error($c, "No email address is set for this user.") unless $c->stash->{user}->emailaddress; # Get all current builds of which this user is a maintainer. $c->stash->{builds} = [$c->model('DB::Builds')->search( diff --git a/src/lib/Hydra/Plugin/GitlabPulls.pm b/src/lib/Hydra/Plugin/GitlabPulls.pm new file mode 100644 index 00000000..b44a1a98 --- /dev/null +++ b/src/lib/Hydra/Plugin/GitlabPulls.pm @@ -0,0 +1,95 @@ +# This plugin allows to build Gitlab merge requests. +# +# The declarative project spec.json file must contains an input such as +# "pulls": { +# "type": "gitlabpulls", +# "value": "https://gitlab.com 42", +# "emailresponsible": false +# } +# where 42 is the project id of a repository. +# +# The values `target_repo_url` and `iid` can then be used to +# build the git input value, e.g.: +# "${target_repo_url} merge-requests/${iid}/head". + +package Hydra::Plugin::GitlabPulls; + +use strict; +use parent 'Hydra::Plugin'; +use HTTP::Request; +use LWP::UserAgent; +use JSON; +use Hydra::Helper::CatalystUtils; +use File::Temp; +use POSIX qw(strftime); + +sub supportedInputTypes { + my ($self, $inputTypes) = @_; + $inputTypes->{'gitlabpulls'} = 'Open Gitlab Merge Requests'; +} + +sub _query { + my ($url, $ua) = @_; + my $req = HTTP::Request->new('GET', $url); + my $res = $ua->request($req); + my $content = $res->decoded_content; + die "Error pulling from the gitlab pulls API: $content\n" + unless $res->is_success; + return (decode_json $content, $res); +} + +sub _iterate { + my ($url, $baseUrl, $pulls, $ua, $target_repo_url) = @_; + my ($pulls_list, $res) = _query($url, $ua); + + foreach my $pull (@$pulls_list) { + $pull->{target_repo_url} = $target_repo_url; + $pulls->{$pull->{iid}} = $pull; + } + # TODO Make Link header parsing more robust!!! + my @links = split ',', $res->header("Link"); + my $next = ""; + foreach my $link (@links) { + my ($url, $rel) = split ";", $link; + if (trim($rel) eq 'rel="next"') { + $next = substr trim($url), 1, -1; + last; + } + } + _iterate($next, $baseUrl, $pulls, $ua, $target_repo_url) unless $next eq ""; +} + +sub fetchInput { + my ($self, $type, $name, $value, $project, $jobset) = @_; + return undef if $type ne "gitlabpulls"; + + (my $baseUrl, my $projectId) = split ' ', $value; + my $url = "$baseUrl/api/v4/projects/$projectId/merge_requests?per_page=100&state=opened"; + + my $accessToken = $self->{config}->{gitlab_authorization}->{$projectId}; + + my %pulls; + my $ua = LWP::UserAgent->new(); + $ua->default_header('Private-Token' => $accessToken) if defined $accessToken; + + # Get the target project URL, as it is the one we need to build the pull + # urls from later + (my $repo, my $res) = _query("$baseUrl/api/v4/projects/$projectId", $ua); + my $target_repo_url = $repo->{http_url_to_repo}; + + _iterate($url, $baseUrl, \%pulls, $ua, $target_repo_url); + + my $tempdir = File::Temp->newdir("gitlab-pulls" . "XXXXX", TMPDIR => 1); + my $filename = "$tempdir/gitlab-pulls.json"; + open(my $fh, ">", $filename) or die "Cannot open $filename for writing: $!"; + print $fh encode_json \%pulls; + close $fh; + system("jq -S . < $filename > $tempdir/gitlab-pulls-sorted.json"); + my $storePath = trim(`nix-store --add "$tempdir/gitlab-pulls-sorted.json"` + or die "cannot copy path $filename to the Nix store.\n"); + chomp $storePath; + my $timestamp = time; + return { storePath => $storePath, revision => strftime "%Y%m%d%H%M%S", gmtime($timestamp) }; +} + +1; diff --git a/src/lib/Hydra/Script/DevServer.pm b/src/lib/Hydra/Script/DevServer.pm new file mode 100644 index 00000000..72934081 --- /dev/null +++ b/src/lib/Hydra/Script/DevServer.pm @@ -0,0 +1,7 @@ +package Hydra::Script::DevServer; +use Moose; +use namespace::autoclean; + +extends 'Catalyst::Script::Server'; + +1; diff --git a/src/root/common.tt b/src/root/common.tt index 6ebeb217..2555718d 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -7,13 +7,27 @@ USE Math; USE mibs=format("%.2f"); - -BLOCK renderDateTime; +# Formatted date time, in hydra-local timezone. +# Use only where an HTML element cannot be used. +BLOCK dateTimeText; date.format(timestamp, '%Y-%m-%d %H:%M:%S'); END; +# HTML-rendered date. Formatted in hydra-local timezone. +# It is enhanced with JavaScript to show user-local and UTC time zones. +BLOCK renderDateTime %] + +[% END; -BLOCK renderRelativeDate; +# Relative date, as text. +# Use only where an HTML element cannot be used. +BLOCK relativeDateText; ago = date.now - timestamp; IF ago >= 0 && ago < 60; THEN; ago _ 's ago'; @@ -28,6 +42,17 @@ BLOCK renderRelativeDate; END; END; +# HTML-rendered relative date. +# It is enhanced with JavaScript to show user-local and UTC time zones. +BLOCK renderRelativeDate %] + +[% END; BLOCK renderProjectName %] [% project %] diff --git a/src/root/layout.tt b/src/root/layout.tt index 554e7b45..2da24cb0 100644 --- a/src/root/layout.tt +++ b/src/root/layout.tt @@ -13,6 +13,7 @@ + @@ -57,7 +58,7 @@ [% IF logo == "" %] Hydra [% ELSE %] - + [% END %]