/
Whateverable.pm6
567 lines (499 loc) · 23.1 KB
/
Whateverable.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# Copyright © 2016-2017
# Aleks-Daniel Jakimenko-Aleksejev <alex.jakimenko@gmail.com>
# Copyright © 2016
# Daniel Green <ddgreen@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use File::Directory::Tree;
use File::Temp;
use HTTP::UserAgent;
use IRC::Client::Message;
use IRC::Client;
use IRC::TextColor;
use JSON::Fast;
use Number::Denominate;
use Pastebin::Gist;
use Terminal::ANSIColor;
use Text::Diff::Sift4;
use Misc;
our $RAKUDO = (%*ENV<TESTABLE> // ‘’).contains(‘rakudo-mock’)
?? ‘./t/data/rakudo’.IO.absolute
!! ‘./data/rakudo-moar’.IO.absolute;
constant MOARVM = ‘./data/moarvm’.IO.absolute;
constant SOURCE = ‘https://github.com/perl6/whateverable’;
constant WIKI = ‘https://github.com/perl6/whateverable/wiki/’;
constant WORKING-DIRECTORY = ‘.’.IO.absolute; # TODO not supported yet
constant ARCHIVES-LOCATION = “{WORKING-DIRECTORY}/data/builds”.IO.absolute;
constant BUILDS-LOCATION = ‘/tmp/whateverable/’.IO.absolute;
constant MESSAGE-LIMIT is export = 260;
constant COMMITS-LIMIT = 500;
our $GIST-LIMIT = 10_000;
constant $CAVE = ‘#whateverable’;
constant $PARENTS = ‘AlexDaniel’, ‘MasterDuke’;
our $RAKUDO-REPO = ‘https://github.com/rakudo/rakudo’;
our $CONFIG = from-json slurp;
constant Message = IRC::Client::Message;
unit role Whateverable[:$default-timeout = 10] does IRC::Client::Plugin does Helpful;
my $default-stdin = slurp ‘stdin’;
method TWEAK {
# wrap around everything to catch exceptions
once { # per class
self.^lookup(‘irc-to-me’).wrap: sub ($self, $msg) {
return if $msg.channel ne $CAVE and $msg.args[1].starts-with: ‘what:’;
# ↑ ideally this check shouldn't be here, but it's much harder otherwise
LEAVE sleep 0.02; # https://github.com/perl6/whateverable/issues/163
try { with (callsame) { return $_ but Reply($msg) } else { return } }
$self.handle-exception: $!, $msg
};
self.^lookup(‘filter’).wrap: sub ($self, $response) {
my &filter = nextcallee;
try { return filter $self, $response }
try { return filter $self, $self.handle-exception($!, $response.?msg) }
‘Sorry kid, that's not my department.’
};
}
# TODO roles should not have TWEAK method
}
method handle-exception($exception, $msg?) {
CATCH { # exception handling is too fat, so let's do this also…
.note;
return ‘Exception was thrown while I was trying to handle another exception…’
~ ‘ What are they gonna do to me, Sarge? What are they gonna do⁈’
}
if $exception ~~ Whateverable::X::HandleableAdHoc { # oh, it's OK!
return $exception.message but Reply($_) with $msg;
return $exception.message
}
note $exception;
with $msg {
if .channel ne $CAVE {
.irc.send-cmd: ‘PRIVMSG’, $CAVE, “I'm acting stupid on {.channel}. Help me.”,
:server(.server), :prefix($PARENTS.join(‘, ’) ~ ‘: ’)
}
}
my ($text, @files) = flat self.awesomify-exception: $exception;
@files .= map({ ‘uncommitted-’ ~ .split(‘/’).tail => .IO.slurp });
@files.push: ‘|git-diff-HEAD.patch’ => run(:out, ‘git’, ‘diff’, ‘HEAD’).out.slurp-rest if @files;
@files.push: ‘result.md’ => $text;
my $return = (‘’ but FileStore(%@files))
but PrettyLink({“No! It wasn't me! It was the one-armed man! Backtrace: $_”});
# https://youtu.be/MC6bzR9qmxM?t=97
$return = $return but Reply($_) with $msg;
$return
}
method awesomify-exception($exception) {
my @local-files;
my $sha = run(:out, ‘git’, ‘rev-parse’, ‘--verify’, ‘HEAD’).out.slurp-rest;
‘<pre>’ ~
$exception.gist.lines.map({
# TODO Proper way to get data out of exceptions?
# For example, right now it is broken for paths with spaces
when /:s ^([\s**2|\s**6]in \w+ \S* at “{WORKING-DIRECTORY}/”?)$<path>=[\S+](
[<.ws>‘(’<-[)]>+‘)’]? line )$<line>=[\d+]$/ {
my $status = run :out, ‘git’, ‘status’, ‘--porcelain’, ‘--untracked-files=no’,
‘--’, ~$<path>;
proceed if !$status && !%*ENV<DEBUGGABLE>; # not a repo file and not in the debug mode
my $private-debugging = !$status;
$status = $status.out.slurp-rest;
my $uncommitted = $status && !$status.starts-with: ‘ ’; # not committed yet
@local-files.push: ~$<path> if $uncommitted || $private-debugging;
my $href = $uncommitted || $private-debugging
?? “#file-uncommitted-{$<path>.split(‘/’).tail.lc.trans(‘.’ => ‘-’)}-” # TODO not perfect but good enough
!! “{SOURCE}/blob/$sha/{markdown-escape $<path>}#”;
$href ~= “L$<line>”;
markdown-escape($0) ~
# let's hope for the best ↓
“<a href="$href">{$<path>}</a>” ~
markdown-escape($1 ~ $<line>) ~
($uncommitted ?? ‘ (⚠ uncommitted)’ !! ‘’)
}
default { $_ }
}).join(“\n”)
~ ‘</pre>’, @local-files
}
multi method irc-to-me(Message $msg where .text ~~
#↓ Matches only one space on purpose (for whitespace-only stdin)
/:i^ [stdin] [‘ ’|‘=’] [clear|delete|reset|unset] $/) {
$default-stdin = slurp ‘stdin’;
‘STDIN is reset to the default value’
}
multi method irc-to-me(Message $msg where .text ~~ /:i^ [stdin] [‘ ’|‘=’] $<stdin>=.* $/) {
$default-stdin = self.process-code: ~$<stdin>, $msg;
“STDIN is set to «{shorten $default-stdin, 200}»” # TODO is 200 a good limit
}
multi method irc-to-me(Message $ where .text ~~ /:i^ [source|url] ‘?’? $/ --> SOURCE) {}
multi method irc-to-me(Message $ where .text ~~ /:i^ wiki ‘?’? $/) { self.get-wiki-link }
multi method irc-to-me(Message $msg where .text ~~ /:i^ help ‘?’? $/) {
self.help($msg) ~ “ # See wiki for more examples: {self.get-wiki-link}”
}
multi method irc-to-me(Message $msg where .text ~~ /:i^ uptime $/) {
use nqp;
use Telemetry;
(denominate now - INIT now) ~ ‘, ’
~ T<max-rss>.fmt(‘%.2f’) ÷ 1024 ~ ‘MiB maxrss. ’
~ (with nqp::getcomp("perl6") {
“This is {.implementation} version {.config<version>} ”
~ “built on {.backend.version_string} ”
~ “implementing {.language_name} {.language_version}.”
})
}
multi method irc-notice-me( $ --> ‘Sorry, it is too private here’) {} # TODO issue #16
multi method irc-privmsg-me($ --> ‘Sorry, it is too private here’) {} # TODO issue #16
multi method irc-to-me($) {
‘I cannot recognize this command. See wiki for some examples: ’ ~ self.get-wiki-link
}
sub I'm-alive is export {
return if %*ENV<TESTABLE> or %*ENV<DEBUGGABLE>;
use NativeCall;
sub sd_notify(int32, str --> int32) is native(‘systemd’) {*};
sd_notify 0, ‘WATCHDOG=1’; # this may be called too often, see TODO below
}
multi method irc-all($) {
# TODO https://github.com/zoffixznet/perl6-IRC-Client/issues/50
I'm-alive;
$.NEXT
}
method get-wiki-link { WIKI ~ self.^name }
method get-short-commit($original-commit) { # TODO not an actual solution tbh
$original-commit ~~ /^ <xdigit> ** 7..40 $/
?? $original-commit.substr(0, 7)
!! $original-commit
}
# TODO $default-timeout is VNNull when working in non-OOP style. Rakudobug it?
sub get-output(*@run-args, :$timeout = $default-timeout || 10,
:$stdin, :$ENV, :$cwd = $*CWD, :$chomp = True) is export {
my $proc = Proc::Async.new: |@run-args;
my $fh-stdin;
LEAVE .close with $fh-stdin;
my $temp-file;
LEAVE unlink $_ with $temp-file;
with $stdin {
if $stdin ~~ IO::Path {
$fh-stdin = $stdin.open
} elsif $stdin ~~ IO::Handle {
$fh-stdin = $stdin
} else {
$temp-file = write-code $stdin;
$fh-stdin = $temp-file.IO.open
}
$proc.bind-stdin: $fh-stdin
}
my @chunks;
my $result;
my $s-start = now;
my $s-end;
react {
whenever $proc.stdout { @chunks.push: $_ }; # RT #131763
whenever $proc.stderr { @chunks.push: $_ };
whenever Promise.in($timeout) {
$proc.kill; # TODO sends HUP, but should kill the process tree instead
@chunks.push: “«timed out after $timeout seconds»”
}
whenever $proc.start: :$ENV, :$cwd { #: scheduler => BEGIN ThreadPoolScheduler.new { # TODO do we need to set scheduler?
$result = $_;
$s-end = now;
done
}
}
my $output = @chunks.join;
%(
output => $chomp ?? $output.chomp !! $output,
exit-code => $result.exitcode,
signal => $result.signal,
time => $s-end - $s-start,
)
}
sub perl6-grep($stdin, $regex is copy, :$timeout = 180, :$complex = False, :$hack = 0) is export {
my $full-commit = to-full-commit ‘HEAD’ ~ (‘^’ x $hack);
die “No build for $full-commit. Oops!” unless build-exists $full-commit;
$regex = “m⦑ $regex ⦒”;
# TODO can we do something smarter?
my $sep = $complex ?? 「“\0\0”」 !! 「“\0”」;
my $magic = “INIT \$*ARGFILES.nl-in = $sep; INIT \$*OUT.nl-out = $sep;”
~ 「use nqp;」
~ 「 next unless」
~ ($complex ?? 「 nqp::substr($_, 0, nqp::index($_, “\0”)) ~~」 !! ‘’) ~ “\n”
~ $regex ~ “;\n”
~ 「last if $++ > 」 ~ $GIST-LIMIT;
my $filename = write-code $magic;
LEAVE unlink $_ with $filename;
my $result = run-snippet $full-commit, $filename, :$timeout, :$stdin, args => (‘-np’,);
my $output = $result<output>;
# numbers less than zero indicate other weird failures ↓
grumble “Something went wrong ($output)” if $result<signal> < 0;
$output ~= “ «exit code = $result<exit-code>»” if $result<exit-code> ≠ 0;
$output ~= “ «exit signal = {Signal($result<signal>)} ($result<signal>)»” if $result<signal> ≠ 0;
grumble $output if $result<exit-code> ≠ 0 or $result<signal> ≠ 0;
my @elems = $output.split: ($complex ?? “\0\0” !! “\0”), :skip-empty;
if @elems > $GIST-LIMIT {
grumble “Cowardly refusing to gist more than $GIST-LIMIT lines”
}
return ‘Found nothing!’ if @elems == 0;
@elems
}
sub fetch-build($full-commit-hash, :$backend!) {
my $ua = HTTP::UserAgent.new;
$ua.timeout = 10;
my $arch = $*KERNEL.name ~ ‘-’ ~ $*KERNEL.hardware;
my $link = “{$CONFIG<mothership>}/$full-commit-hash?type=$backend&arch=$arch”;
note “Attempting to fetch $full-commit-hash…”;
my $response = $ua.get: :bin, $link;
return unless $response.is-success;
my $disposition = $response.header.field(‘Content-Disposition’).values[0];
return unless $disposition ~~ /‘filename=’\s*(<.xdigit>+[‘.zst’|‘.lrz’])/;
my $location = ARCHIVES-LOCATION.IO.add: $backend;
my $archive = $location.add: ~$0;
spurt $archive, $response.content, :bin;
if $archive.ends-with: ‘.lrz’ { # populate symlinks
my $proc = run :out, :bin, <lrzip -dqo - -->, $archive;
my $list = run :in($proc.out), :out, <tar --list --absolute-names>;
my @builds = gather for $list.out.lines { # TODO assumes paths without newlines, dumb but I don't see another way
take ~$0 if /^‘/tmp/whateverable/’$backend‘/’(<.xdigit>+)‘/’/;
}
for @builds.unique {
my $symlink = $location.add: $_;
$symlink.unlink if $symlink.e; # remove existing (just in case)
$archive.IO.symlink: $symlink;
}
}
return $archive
}
sub build-exists($full-commit-hash, :$backend=‘rakudo-moar’) is export {
my $archive = “{ARCHIVES-LOCATION}/$backend/$full-commit-hash.zst”.IO;
my $archive-lts = “{ARCHIVES-LOCATION}/$backend/$full-commit-hash”.IO;
# ↑ long-term storage (symlink to a large archive)
my $answer = ($archive, $archive-lts).any.e.so;
return so fetch-build $full-commit-hash, :$backend if !$answer && $CONFIG<mothership>;
$answer
}
method get-similar($tag-or-hash, @other?, :$repo=$RAKUDO) {
my @options = @other;
my @tags = get-output(cwd => $repo, ‘git’, ‘tag’,
‘--format=%(*objectname)/%(objectname)/%(refname:strip=2)’,
‘--sort=-taggerdate’)<output>.lines
.map(*.split(‘/’))
.grep({ build-exists .[0] || .[1] })
.map(*[2]);
my $cutoff = $tag-or-hash.chars max 7;
my @commits = get-output(cwd => $repo, ‘git’, ‘rev-list’,
‘--all’, ‘--since=2014-01-01’)<output>
.lines.map(*.substr: 0, $cutoff);
# flat(@options, @tags, @commits).min: { sift4($_, $tag-or-hash, 5, 8) }
my $ans = ‘HEAD’;
my $ans_min = ∞;
for flat @options, @tags, @commits {
my $dist = sift4 $_, $tag-or-hash, $cutoff;
if $dist < $ans_min {
$ans = $_;
$ans_min = $dist;
}
}
$ans
}
sub run-smth($full-commit-hash, $code, :$backend=‘rakudo-moar’) is export {
my $build-prepath = “{BUILDS-LOCATION}/$backend”;
my $build-path = “$build-prepath/$full-commit-hash”;
my $archive-path = “{ARCHIVES-LOCATION}/$backend/$full-commit-hash.zst”;
my $archive-link = “{ARCHIVES-LOCATION}/$backend/$full-commit-hash”;
mkdir $build-prepath; # create all parent directories just in case
# (may be needed for isolated /tmp)
# lock on the destination directory to make
# sure that other bots will not get in our way.
while run(:err(Nil), ‘mkdir’, ‘--’, $build-path).exitcode ≠ 0 {
if %*ENV<TESTABLE> {
use NativeCall;
sub kill(int32, int32) is native {*};
sub getppid(--> int32) is native {*};
kill getppid, 10; # SIGUSR1
}
note “$build-path is locked. Waiting…”;
sleep 0.5 # should never happen if setup correctly
}
if $archive-path.IO ~~ :e {
my $proc = run :out, :bin, ‘pzstd’, ‘-dqc’, ‘--’, $archive-path;
run :in($proc.out), :bin, ‘tar’, ‘x’, ‘--absolute-names’;
} else {
my $proc = run :out, :bin, ‘lrzip’, ‘-dqo’, ‘-’, ‘--’, $archive-link;
run :in($proc.out), :bin, ‘tar’, ‘--extract’, ‘--absolute-names’, ‘--’, $build-path;
}
my $return = $code($build-path); # basically, we wrap around $code
rmtree $build-path;
$return
}
# TODO $default-timeout is VNNull when working in non-OOP style. Rakudobug it?
sub run-snippet($full-commit-hash, $file, :$backend=‘rakudo-moar’, :@args=Empty,
:$timeout=$default-timeout||10, :$stdin=$default-stdin, :$ENV) is export {
run-smth :$backend, $full-commit-hash, -> $path {
my $binary-path = $path.IO.add: ‘bin/perl6’;
my %tweaked-env = $ENV // %*ENV;
%tweaked-env<PATH> = join ‘:’, $binary-path.parent, (%tweaked-env<PATH> // Empty);
$binary-path.IO !~~ :e
?? %(output => ‘Commit exists, but a perl6 executable could not be built for it’,
exit-code => -1, signal => -1, time => -1,)
!! get-output $binary-path, |@args,
‘--’, $file, :$stdin, :$timeout, ENV => %tweaked-env, :!chomp
}
}
method get-commits($_, :$repo=$RAKUDO) {
return .split: /‘,’\s*/ if .contains: ‘,’;
if /^ $<start>=\S+ ‘..’ $<end>=\S+ $/ {
if run(:out(Nil), :err(Nil), :cwd($repo),
‘git’, ‘rev-parse’, ‘--verify’, $<start>).exitcode ≠ 0 {
grumble “Bad start, cannot find a commit for “$<start>””
}
if run(:out(Nil), :err(Nil), :cwd($repo),
‘git’, ‘rev-parse’, ‘--verify’, $<end>).exitcode ≠ 0 {
grumble “Bad end, cannot find a commit for “$<end>””
}
my $result = get-output :cwd($repo), ‘git’, ‘rev-list’, ‘--reverse’,
“$<start>^..$<end>”; # TODO unfiltered input
grumble ‘Couldn't find anything in the range’ if $result<exit-code> ≠ 0;
my @commits = $result<output>.lines;
if @commits.elems > COMMITS-LIMIT {
grumble “Too many commits ({@commits.elems}) in range, you're only allowed {COMMITS-LIMIT}”
}
return @commits
}
return self.get-tags: ‘2015-12-24’, :$repo if /:i ^ [ releases | v? 6 ‘.’? c ] $/;
return self.get-tags: ‘2014-01-01’, :$repo if /:i ^ all $/;
return ~$<commit> if /:i ^ compare \s $<commit>=\S+ $/;
return $_
}
method get-tags($date, :$repo=$RAKUDO) {
my @tags = <HEAD>;
my %seen;
for get-output(cwd => $repo, ‘git’, ‘log’, ‘--pretty="%d"’,
‘--tags’, ‘--no-walk’, “--since=$date”)<output>.lines -> $tag {
next unless $tag ~~ /:i ‘tag:’ \s* ((\d\d\d\d\.\d\d)[\.\d\d?]?) /; # TODO use tag -l
next if %seen{$0[0]}++;
@tags.push($0)
}
@tags.reverse
}
sub to-full-commit($commit, :$short=False, :$repo=$RAKUDO) is export {
return if run(:out(Nil), :err(Nil), :cwd($repo),
‘git’, ‘rev-parse’, ‘--verify’, $commit).exitcode ≠ 0; # make sure that $commit is valid
my $result = get-output cwd => $repo,
|(‘git’, ‘rev-list’, ‘-1’, # use rev-list to handle tags
($short ?? ‘--abbrev-commit’ !! Empty), $commit);
return if $result<exit-code> ≠ 0;
return unless $result<output>;
$result<output>
}
sub write-code($code) is export {
my ($filename, $filehandle) = tempfile :!unlink;
$filehandle.print: $code;
$filehandle.close;
$filename
}
sub process-url($url, $msg) is export {
my $ua = HTTP::UserAgent.new;
my $response;
try {
$response = $ua.get: $url;
CATCH {
grumble ‘It looks like a URL, but for some reason I cannot download it’
~ “ ({.message})”
}
}
if not $response.is-success {
grumble ‘It looks like a URL, but for some reason I cannot download it’
~ “ (HTTP status line is {$response.status-line}).”
}
if not $response.content-type.contains: ‘text/plain’ | ‘perl’ {
grumble “It looks like a URL, but mime type is ‘{$response.content-type}’”
~ ‘ while I was expecting something with ‘text/plain’ or ‘perl’’
~ ‘ in it. I can only understand raw links, sorry.’
}
my $body = $response.decoded-content;
.reply: ‘Successfully fetched the code from the provided URL.’ with $msg;
sleep 0.02; # https://github.com/perl6/whateverable/issues/163
$body
}
method process-code($code is copy, $msg) {
$code ~~ m{^ ( ‘http’ s? ‘://’ \S+ ) }
?? process-url(~$0, $msg)
!! $code.subst: :g, ‘’, “\n”
}
multi method filter($response where (.encode.elems > MESSAGE-LIMIT
or ?.?additional-files
or (!~$_ and $_ ~~ ProperStr))) {
# Here $response is a Str with a lot of stuff mixed in (possibly)
my $description = ‘Whateverable’;
my $text = colorstrip $response.?long-str // ~$response;
my %files;
%files<result> = $text if $text;
%files.push: $_ with $response.?additional-files;
if $response ~~ Reply {
$description = $response.msg.server.current-nick;
%files<query> = $_ with $response.?msg.text;
%files<query>:delete unless %files<query>;
}
my $url = self.upload: %files, public => !%*ENV<DEBUGGABLE>, :$description;
$url = $response.link-msg()($url) if $response ~~ PrettyLink;
$url
}
multi method filter($text is copy) {
ansi-to-irc($text).trans:
“\n” => ‘’,
3.chr => 3.chr, 0xF.chr => 0xF.chr, # keep these for IRC colors
|((^32)».chr Z=> (0x2400..*).map(*.chr)), # convert all unreadable ASCII crap
127.chr => ‘␡’, /<:Cc>/ => ‘␦’
}
method upload(%files is copy, :$description = ‘’, Bool :$public = True) {
if %*ENV<TESTABLE> {
my $nick = $.irc.servers.values[0].current-nick;
my $gists-path = “{BUILDS-LOCATION}/tist/$nick”;
rmtree $gists-path if $gists-path.IO ~~ :d;
mkdir $gists-path;
spurt “$gists-path/{.key}”, .value for %files;
return ‘https://whatever.able/fakeupload’;
}
%files = %files.pairs.map: { .key => %( ‘content’ => .value ) }; # github format
my $gist = Pastebin::Gist.new(token => $CONFIG<github><access_token> || Nil);
return $gist.paste: %files, desc => $description, public => $public
}
method selfrun($nick is copy, @alias?) {
$nick ~= ‘test’ if %*ENV<DEBUGGABLE>;
.run with IRC::Client.new(
:$nick
:userreal($nick.tc)
:username($nick.substr(0, 3) ~ ‘-able’)
:password(?%*ENV<TESTABLE> ?? ‘’ !! $CONFIG<irc><login password>.join: ‘:’)
:@alias
# IPv4 address of chat.freenode.net is hardcoded so that we can double the limit ↓
:host(%*ENV<TESTABLE> ?? ‘127.0.0.1’ !! (‘chat.freenode.net’, ‘185.30.166.38’).pick)
:channels(%*ENV<DEBUGGABLE>
?? ‘#whateverable’
!! %*ENV<TESTABLE>
?? “#whateverable_$nick”
!! (|<#perl6 #perl6-dev #zofbot #moarvm>, $CAVE) )
:debug(?%*ENV<DEBUGGABLE>)
:plugins(self)
:filters( -> |c { self.filter(|c) } )
)
}
# TODO move somewhere
# TODO commit unused
sub subprocess-commit($commit, $filename, $full-commit, :%ENV) is export {
return ‘No build for this commit’ unless build-exists $full-commit;
$_ = run-snippet $full-commit, $filename, :%ENV; # actually run the code
# numbers less than zero indicate other weird failures ↓
return “Cannot test this commit ($_<output>)” if .<signal> < 0;
my $output = .<output>;
$output ~= “ «exit code = $_<exit-code>»” if .<exit-code> ≠ 0;
$output ~= “ «exit signal = {Signal($_<signal>)} ($_<signal>)»” if .<signal> ≠ 0;
$output
}
# vim: expandtab shiftwidth=4 ft=perl6