Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial attempt at adding graphing to benchable
This works, but requires cloning the gist onto the filesystem and doing git add, git commit, git push
  • Loading branch information
MasterDuke17 committed Jul 17, 2016
1 parent 57bd995 commit 669e5c7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 28 deletions.
54 changes: 27 additions & 27 deletions Perl6IRCBotable.pm
Expand Up @@ -34,10 +34,20 @@ use JSON::XS;
use Net::GitHub;
use Time::HiRes qw(time);

use constant RAKUDO => './rakudo';
use constant RAKUDO => abs_path('./rakudo');
use constant BUILDS => abs_path('./builds');
use constant CONFIG => abs_path('./config.json');
use constant SOURCE => 'https://github.com/perl6/bisectbot';
use constant GHCONF => decode_json(
do {
local $/;
open my $fh, '<:encoding(UTF-8)', CONFIG or die "No config file found";
<$fh>;
});
use constant GHGIST => Net::GitHub->new(
login => GHCONF->{'login'},
access_token => GHCONF->{'access_token'},
)->gist;

sub get_output {
my $self = shift;
Expand Down Expand Up @@ -121,38 +131,25 @@ sub process_code {
return (1, $code)
}

sub get_config {
my $config_contents = do {
local $/;
open my $fh, '<:encoding(UTF-8)', CONFIG or die "No config file found";
<$fh>;
};
sub upload_to_gist {
my ($self, $gist, $files) = @_;

my $config = decode_json $config_contents; # TODO do it only once
return $config
my %files_param = map { $_ => { 'content' => encode_utf8($files->{$_}) } } keys %$files; # github format

GHGIST->update($gist->{'id'}, { 'files' => \%files_param, });
}

sub upload {
sub create_gist {
my ($self, $files) = @_;

my $config = get_config;
my $github = Net::GitHub->new(
login => $config->{'login'},
access_token => $config->{'access_token'},
);

my $gist = $github->gist;

my %files_param = map { $_ => { 'content' => encode_utf8($files->{$_}) } } keys %$files; # github format

my $res = $gist->create(
return GHGIST->create(
{
'description' => $self->nick,
'public' => 'true',
'files' => \%files_param,
description => $self->nick,
public => 'true',
files => \%files_param,
});

return $res->{html_url}
}

sub said {
Expand All @@ -163,10 +160,13 @@ sub said {
return SOURCE if $body eq 'source';
return 'Sorry, it is too private here' if $message->{address} eq 'msg';

my $response = $self->process_message($message, $body);
my ($gist, $response) = $self->process_message($message, $body);
if (length $response > 250) { # upload code somewhere if the output is way too long
$response = $self->upload({ 'query' => $body,
'result' => $response, });
$response = $self->upload_to_gist(
$gist // GHGIST->create_gist({ 'undefined' => $body, }),
$gist->{'id'},
{ result => $response, }
);
} else {
$response =~ s/\n//g;
}
Expand Down
33 changes: 32 additions & 1 deletion benchable.pl
Expand Up @@ -25,7 +25,9 @@ package Benchable;
use parent 'Perl6IRCBotable';

use Cwd qw(cwd abs_path);
use File::Temp qw(tempfile tempdir);
use List::Util qw(min);
use Chart::Gnuplot;

use constant LIMIT => 300;

Expand All @@ -35,6 +37,7 @@ sub process_message {
my ($self, $message, $body) = @_;

my $msg_response = '';
my $gist = undef;

if ($body =~ /^ \s* (\S+) \s+ (.+) /xu) {
my ($config, $code) = ($1, $2);
Expand Down Expand Up @@ -89,12 +92,40 @@ sub process_message {
}
}

if (scalar @commits >= 5) {
my ($gfh, $gfilename) = tempfile(SUFFIX => '.svg', UNLINK => 1);
my $chart = Chart::Gnuplot->new(
output => $gfilename,
terminal => 'svg mousing',
xlabel => 'Commits',
ylabel => 'Seconds',
xtics => { labels => [map { "'$commits[$_]' $_" } 0..$#commits], },
);
my $dataSet = Chart::Gnuplot::DataSet->new(
ydata => [map { $times{substr($_, 0, 7)} } @commits],
style => 'linespoints',
);
$chart->plot2d($dataSet);

$gist = $self->create_gist({ query => $body, });

my $dir = tempdir(CLEANUP => 1);
chdir $dir;
system('git', 'clone', "git\@gist.github.com:$gist->{'id'}");
chdir $gist->{'id'};
system('cp', $gfilename, '.');
system('git', 'add', '.');
system('git', 'commit', '-m', 'Graph of benchmark results');
system('git', 'push');
chdir $self->RAKUDO;
}

$msg_response .= '|' . join("\n|", map { $_ = substr($_, 0, 7); "«$_»:$times{$_}" } @commits);
} else {
return help();
}

return $msg_response;
return ($gist, $msg_response);
}

sub help {
Expand Down

0 comments on commit 669e5c7

Please sign in to comment.