From 29a4d771fb06c00b767d58c38fd7160a3245c3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20B=C3=B6ker?= Date: Tue, 7 Nov 2023 22:52:37 +0100 Subject: [PATCH] Get re-testing via website working Forward to the test-set afterwards is TBD. --- lib/CITestSetManager.rakumod | 4 ++-- lib/DB.rakumod | 6 +++--- lib/GitHubCITestRequester.rakumod | 18 ++++++++++-------- lib/Routes.rakumod | 17 +---------------- lib/Routes/testset.rakumod | 30 ++++++++++++++++++++++++++++-- resources/templates/testset.crotmp | 8 +++++++- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/lib/CITestSetManager.rakumod b/lib/CITestSetManager.rakumod index b0af867..f918f50 100644 --- a/lib/CITestSetManager.rakumod +++ b/lib/CITestSetManager.rakumod @@ -40,7 +40,7 @@ method process-worklist() is serial-dedup { $command.^save; } else { - $ts = $command.ts; + $ts = $command.test-set; } debug "CITestSetManager: Starting re-test for command: " ~ $command.id; @@ -113,7 +113,7 @@ method add-test-set(:$test-set!, :$source-spec!) { self.process-worklist; } -method re-test(:$test-set!) { +method re-test($test-set) { DB::Command.^create: :command(DB::RE_TEST), :$test-set, diff --git a/lib/DB.rakumod b/lib/DB.rakumod index 260c4f8..c25fa2e 100644 --- a/lib/DB.rakumod +++ b/lib/DB.rakumod @@ -230,9 +230,9 @@ model Command is rw is table { # If triggered via a GitHub PR comment has UInt $!fk-pr is referencing( *.id, :model(DB::GitHubPR) ); has DB::GitHubPR $.pr is relationship( *.fk-pr ); - has Str $.comment-author is column; - has Str $.comment-id is column; - has Str $.comment-url is column; + has Str $.comment-author is column{ :nullable }; + has Str $.comment-id is column{ :nullable }; + has Str $.comment-url is column{ :nullable }; has DB::CommandStatus $.status is column = DB::COMMAND_NEW; has DB::CommandEnum $.command is column; diff --git a/lib/GitHubCITestRequester.rakumod b/lib/GitHubCITestRequester.rakumod index c8f4cd8..6a8e02a 100644 --- a/lib/GitHubCITestRequester.rakumod +++ b/lib/GitHubCITestRequester.rakumod @@ -574,12 +574,14 @@ method !process-merge-on-success() { } method command-accepted($command) { - my $proj-repo = self!db-project-to-project-repo($command.pr.project); - - $!github-interface.add-issue-comment: - owner => $proj-repo, - repo => $proj-repo, - number => $command.pr.number, - body => ($command.command == DB::RE_TEST ?? "@" ~ $command.comment-author ~ " Re-testing of this PR started." !! - "What? I confused myself!"); + with $command.pr { + my $proj-repo = self!db-project-to-project-repo($command.pr.project); + + $!github-interface.add-issue-comment: + owner => $proj-repo, + repo => $proj-repo, + number => $command.pr.number, + body => ($command.command == DB::RE_TEST ?? "@" ~ $command.comment-author ~ " Re-testing of this PR started." !! + "What? I confused myself!"); + } } diff --git a/lib/Routes.rakumod b/lib/Routes.rakumod index db21bdc..61b539c 100644 --- a/lib/Routes.rakumod +++ b/lib/Routes.rakumod @@ -83,24 +83,9 @@ sub routes(CITestSetManager $tsm, SourceArchiveCreator $sac, GitHubInterface $gi redirect decode-percents($state); } - post -> Cro::HTTP::Auth $session, "retest", $testset-id { - my $gh-token = $session.token; - my $gh-user = $session.token; - - my $ts = DB::CITestSet.^load: :id($testset-id); - my $conf = config.projects.for-id($ts.pr.project); - if $github-interface.can-user-merge-repo(owner => $conf.project, repo => $conf.repo, username => $gh-user) { - $tsm.re-test($ts); - created "/testset/$testset-id"; - } - else { - forbidden; - } - } - include home-routes(&gen-login-data); include test-routes(&gen-login-data); - include testset-routes($sac, &gen-login-data); + include testset-routes($sac, $tsm, $github-interface, &gen-login-data); include source-routes($sac); include github-hook-routes($github-interface); } diff --git a/lib/Routes/testset.rakumod b/lib/Routes/testset.rakumod index 6b42101..de7dace 100644 --- a/lib/Routes/testset.rakumod +++ b/lib/Routes/testset.rakumod @@ -1,13 +1,37 @@ use DB; use Formatters; +use Config; use Cro::HTTP::Router; use Cro::WebApp::Template; use Red::Operators:api<2>; -sub testset-routes($sac, &gen-login-data) is export { +sub testset-routes($sac, $tsm, $github-interface, &gen-login-data) is export { route { + post -> Cro::HTTP::Auth $session, "testset", UInt $id, :$command where "retest" { + my $gh-token = $session.token; + my $gh-user = $session.token; + + my $ts = DB::CITestSet.^load: :$id; + my $conf = config.projects.for-id($ts.project); + if $github-interface.can-user-merge-repo(owner => $conf.project, repo => $conf.repo, username => $gh-user) { + $tsm.re-test($ts); + created "/testset/$id"; + } + else { + forbidden; + } + } + + get -> Cro::HTTP::Auth $session, "testset", UInt $id { + make-testset-page($id, True); + } + get -> "testset", UInt $id { + make-testset-page($id, False); + } + + sub make-testset-page($id, $logged-in) { with DB::CITestSet.^load($id) { sub order-tests(@tests) { my @ordered = @tests.grep(!*.superseded); @@ -28,7 +52,7 @@ sub testset-routes($sac, &gen-login-data) is export { }; } my %data = - login-url => gen-login-data("/testset/$id"), + login-data => gen-login-data("/testset/$id"), id => .id, created-at => .creation, project => .project, @@ -39,6 +63,8 @@ sub testset-routes($sac, &gen-login-data) is export { (.status != DB::DONE ?? "in-progress" !! ([&&] .platform-test-sets.Seq.map({ $_.tests.Seq.map({.superseded || .status == DB::SUCCESS}) }).flat) ?? "success" !! "failure"), error => .error, + :$logged-in, + retest-url => "/testset/$id?command=retest", rakudo-git-url => .source-spec.rakudo-git-url, rakudo-commit-sha => .source-spec.rakudo-commit-sha, nqp-git-url => .source-spec.nqp-git-url, diff --git a/resources/templates/testset.crotmp b/resources/templates/testset.crotmp index 0d044dc..fc2ee6a 100644 --- a/resources/templates/testset.crotmp +++ b/resources/templates/testset.crotmp @@ -1,5 +1,5 @@ <:use 'page.crotmp'> -<|page('Test Set', .login-url)> +<|page('Test Set', .login-data)>

Test Set <.id>

@@ -21,6 +21,12 @@
+ +
+ +
+ +

Tests

<@.backends>

<.name> <.id>