Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use the GitHub gist API
  • Loading branch information
Mouq committed Jun 6, 2015
1 parent 9002c38 commit 4a18f52
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/EvalbotExecuter.pm
Expand Up @@ -76,15 +76,20 @@ use Encode qw(encode);
use charnames qw(:full);
use POSIX ();
use Encode qw/decode_utf8/;
use JSON qw/decode_json/;

my $max_output_len = 290;

sub run {
my ($program, $executer, $ename) = @_;
if ($program =~ /^https:\/\/gist\.github\.com\/[^\/]+?\/\p{HexDigit}+$/) {
my $page = `curl -s $program`;
$page =~ /<a\b[^>]+?\baria-label="View Raw"[^>]+?\bhref="([^"]+)"/;
if ($1) { $program = decode_utf8 `curl -s https://gist.githubusercontent.com$1` } else { return 'gist not found' };
if ($program =~ /^https:\/\/gist\.github\.com\/[^\/]+?\/(\p{HexDigit}+)$/) {
my $page = `curl -s https://api.github.com/gists/$1`;
my $json = decode_json $page;
if ($json->{message} && $json->{message} eq 'Not Found') {
return 'gist not found';
} else {
$program = (values %{$json->{files}})[0]{content};
}
} elsif ($program =~ /^https:\/\/github\.com\/([^\/]+\/[^\/]+)\/blob\/([^\/]+\/[^\/].*)$/) {
my ($project, $file) = ($1, $2);
my $page = `curl -s $program`;
Expand Down

0 comments on commit 4a18f52

Please sign in to comment.