Skip to content

Commit 55a10e8

Browse files
committed
Allow bot name as a prefix
Given that people still try to do 「bisectable: somecodehere」, it is time to allow it. Note that 「bisectable: bisect: somecodehere」 is still not valid. If you do that, it will run fine because “bisect:” will be treated as a Perl 6 label, but that's still misuse.
1 parent 183b6d2 commit 55a10e8

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

bot.pl

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,29 @@ sub to_commit {
5555

5656
sub said {
5757
my ($self, $message) = @_;
58-
if ($message->{body} =~ /^bisect:
58+
59+
if ($message->{body} eq 'source') {
60+
return 'https://github.com/perl6/bisectbot';
61+
}
62+
63+
my $start = defined $message->{address} ? '' : 'bisect:';
64+
say $start;
65+
if ($message->{body} =~ /^ $start \s*
5966
(?:
60-
(?: \s+ good (?: \s*=\s* | \s+) ([^\s]+) )
61-
(?: \s+ bad (?: \s*=\s* | \s+) ([^\s]+) )?
67+
(?: good (?: \s*=\s* | \s+) ([^\s]+) \s+ )
68+
(?: bad (?: \s*=\s* | \s+) ([^\s]+) \s+ )?
6269
|
63-
(?: \s+ bad (?: \s*=\s* | \s+) ([^\s]+) )?
64-
(?: \s+ good (?: \s*=\s* | \s+) ([^\s]+) )?
70+
(?: bad (?: \s*=\s* | \s+) ([^\s]+) \s+ )?
71+
(?: good (?: \s*=\s* | \s+) ([^\s]+) \s+ )?
6572
)
6673
(*PRUNE)
67-
\s+ (.+)
74+
(.+)
6875
/xu) {
69-
if (defined $message->{address}) {
76+
if ($message->{address} eq 'msg') {
7077
return 'Sorry, it is too private here';
7178
}
79+
my $answer_start = $message->{address} ? '' : "$message->{who}: ";
80+
7281
my $good = $1 // $4 // '2015.12';
7382
my $bad = $2 // $3 // 'HEAD';
7483
my $code = $5;
@@ -86,28 +95,28 @@ sub said {
8695
chdir($rakudo);
8796
$good = to_commit($good);
8897
chdir($oldDir);
89-
return "$message->{who}: cannot find such “good” revision" unless defined $good;
90-
return "$message->{who}: no build for such “good” revision" if ! -e "$builds/$good/bin/perl6";
98+
return "${answer_start}cannot find such “good” revision" unless defined $good;
99+
return "${answer_start}no build for such “good” revision" if ! -e "$builds/$good/bin/perl6";
91100
chdir($rakudo);
92101
$bad = to_commit($bad);
93102
chdir($oldDir);
94-
return "$message->{who}: cannot find such “bad” revision" unless defined $bad;
103+
return "${answer_start}cannot find such “bad” revision" unless defined $bad;
95104
if (! -e "$builds/$bad/bin/perl6" and -e $build_lock) {
96105
# TODO fix the problem when it is building new commits
97-
return "$message->{who}: no build for such “bad” revision. Right now the build process is in action, please try again later or specify some older “bad” commit (e.g. bad=HEAD~40)";
106+
return "${answer_start}no build for such “bad” revision. Right now the build process is in action, please try again later or specify some older “bad” commit (e.g. bad=HEAD~40)";
98107
}
99-
return "$message->{who}: no build for such “bad” revision" if ! -e "$builds/$bad/bin/perl6";
108+
return "${answer_start}no build for such “bad” revision" if ! -e "$builds/$bad/bin/perl6";
100109

101110
my ($out_good, $exit_good) = get_output("$builds/$good/bin/perl6", $filename);
102111
my ($out_bad, $exit_bad) = get_output("$builds/$bad/bin/perl6", $filename);
103112
if ($exit_good == $exit_bad and $out_good eq $out_bad) {
104-
return "$message->{who}: on both starting points the exit code is $exit_bad and the output is identical as well";
113+
return "${answer_start}on both starting points the exit code is $exit_bad and the output is identical as well";
105114
}
106115
my $output_file = '';
107116
if ($exit_good == $exit_bad) {
108117
$self->say(
109118
channel => $message->{channel},
110-
body => "$message->{who}: exit code is $exit_bad on both starting points, bisecting by using the output",
119+
body => "${answer_start}exit code is $exit_bad on both starting points, bisecting by using the output",
111120
);
112121
(my $fh, $output_file) = tempfile(UNLINK => 1);
113122
print $fh $out_good;
@@ -116,7 +125,7 @@ sub said {
116125
if ($exit_good != $exit_bad and $exit_good != 0) {
117126
$self->say(
118127
channel => $message->{channel},
119-
body => "$message->{who}: exit code on a “good” revision is $exit_good (which is bad), bisecting with inverted logic",
128+
body => "${answer_start}exit code on a “good” revision is $exit_good (which is bad), bisecting with inverted logic",
120129
);
121130
}
122131

@@ -139,14 +148,11 @@ sub said {
139148
}
140149
if ($bisect_status != 0) {
141150
chdir($oldDir);
142-
return "$message->{who}: “bisect run” failure";
151+
return "${answer_start}“bisect run” failure";
143152
}
144153
my ($result) = get_output('git', 'show', '--quiet', '--date=short', "--pretty=(%cd) $link/%h", 'bisect/bad');
145154
chdir($oldDir);
146-
return "$message->{who}: $result";
147-
}
148-
if ($message->{body} eq 'source') {
149-
return 'https://github.com/perl6/bisectbot';
155+
return "${answer_start}$result";
150156
}
151157
}
152158

0 commit comments

Comments
 (0)