Skip to content

Commit

Permalink
Get re-testing via website working
Browse files Browse the repository at this point in the history
Forward to the test-set afterwards is TBD.
  • Loading branch information
patrickbkr committed Nov 7, 2023
1 parent e5042b4 commit 29a4d77
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
4 changes: 2 additions & 2 deletions lib/CITestSetManager.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lib/DB.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ model Command is rw is table<command> {
# 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;
Expand Down
18 changes: 10 additions & 8 deletions lib/GitHubCITestRequester.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -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<project>,
repo => $proj-repo<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<project>,
repo => $proj-repo<repo>,
number => $command.pr.number,
body => ($command.command == DB::RE_TEST ?? "@" ~ $command.comment-author ~ " Re-testing of this PR started." !!
"What? I confused myself!");
}
}
17 changes: 1 addition & 16 deletions lib/Routes.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -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<gh-token>;
my $gh-user = $session.token<username>;

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);
}
Expand Down
30 changes: 28 additions & 2 deletions lib/Routes/testset.rakumod
Original file line number Diff line number Diff line change
@@ -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<gh-token>;
my $gh-user = $session.token<username>;

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);
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion resources/templates/testset.crotmp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<:use 'page.crotmp'>
<|page('Test Set', .login-url)>
<|page('Test Set', .login-data)>
<h1>Test Set <.id> <div class="status-indicator <.status-indicator-class>"></div></h1>

<div class="cols">
Expand All @@ -21,6 +21,12 @@
</ul></div>
</div>

<?.logged-in>
<form action="<.retest-url>" method="post">
<input type="submit" value="Re-test">
</form>
</?>

<h1>Tests</h1>
<@.backends>
<h2><.name> <.id></h2>
Expand Down

0 comments on commit 29a4d77

Please sign in to comment.