Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use github gists for long output
  • Loading branch information
AlexDaniel committed Jul 14, 2016
1 parent 8e71350 commit 82d4ca8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
rakudo
builds
logs
config.json
46 changes: 41 additions & 5 deletions Perl6IRCBotable.pm
Expand Up @@ -29,11 +29,14 @@ use Cwd qw(cwd abs_path);
use IO::Handle;
use IPC::Open3;
use HTTP::Tiny;
use Encode qw(decode_utf8);
use Encode qw(encode_utf8 decode_utf8);
use Time::HiRes qw(time);
use Net::GitHub;
use JSON::XS;

use constant RAKUDO => './rakudo';
use constant BUILDS => abs_path('./builds');
use constant CONFIG => './config.json';
use constant SOURCE => 'https://github.com/perl6/bisectbot';

my $name = 'Perl6IRCBotable';
Expand Down Expand Up @@ -123,10 +126,38 @@ sub process_code {
return (1, $code);
}

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

return $output;
my $config = decode_json $config_contents; # TODO do it only once
return $config;
}

sub upload {
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(
{
'description' => "the description for this gist",
'public' => 'true',
'files' => \%files_param,
});

return $res->{html_url};
}

sub said {
Expand All @@ -144,7 +175,12 @@ sub said {
return 'Sorry, it is too private here';
} else {
my $response = $self->process_message($message, $body);
$response = $self->upload_output($response) if (length $response > 500);
if (length $response > 250) {
$response = $self->upload({ 'query' => $body,
'result' => $response, });
} else {
$response =~ s/\n//g;
}

$self->say(
channel => $message->{channel},
Expand Down
1 change: 0 additions & 1 deletion committable.pl
Expand Up @@ -78,7 +78,6 @@ sub process_message {
chdir $self->RAKUDO;
my ($out, $exit, $time) = $self->get_output($self->BUILDS . "/$full_commit/bin/perl6", $filename);
chdir $old_dir;
$out =~ s/\n//g if (defined $out);

$msg_response .= "$commit: " . ($out // '') . " ";
$msg_response .= " exit code = $exit" if ($exit != 0);
Expand Down
4 changes: 4 additions & 0 deletions config.json
@@ -0,0 +1,4 @@
{
"login": "foo",
"access_token": "bar"
}

0 comments on commit 82d4ca8

Please sign in to comment.