Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #5 from MasterDuke17/master
Fix URL processing
  • Loading branch information
AlexDaniel committed Jul 14, 2016
2 parents 5e6290f + 77d06e2 commit be6da9e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
34 changes: 22 additions & 12 deletions Perl6IRCBotable.pm
Expand Up @@ -88,12 +88,12 @@ sub process_url {

my $response = HTTP::Tiny->new->get($url); # $body is actually a url
if (not $response->{success}) {
return "$message->{who}:It looks like a URL, but for some reason I cannot download it"
. " (HTTP status-code is $response->{status})",;
return (0, "$message->{who}:It looks like a URL, but for some reason I cannot download it"
. " (HTTP status-code is $response->{status}).");
}
if ($response->{headers}->{'content-type'} ne 'text/plain; charset=utf-8') {
return "$message->{who}:It looks like a URL, but mime type is '$response->{headers}->{'content-type'}'"
. " while I was expecting 'text/plain; charset=utf-8'. I can only understand raw links, sorry.";
return (0, "$message->{who}:It looks like a URL, but mime type is '$response->{headers}->{'content-type'}'"
. " while I was expecting 'text/plain; charset=utf-8'. I can only understand raw links, sorry.");
}
my $body = decode_utf8($response->{content});
$self->say(
Expand All @@ -102,7 +102,24 @@ sub process_url {
who => $message->{who},
);

return $body;
return (1, $body);
}

sub process_code {
my ($self, $code) = @_;

if ($code =~ m{ ^https?:// }x ) {
my ($succeeded, $response) = $self->process_url($code);
if ($succeeded) {
$code = $response;
} else {
return (0, $response);
}
} else {
$code =~ s//\n/g;
}

return (1, $code);
}

sub upload_output {
Expand All @@ -125,13 +142,6 @@ sub said {
if ($message->{address} eq 'msg') {
return 'Sorry, it is too private here';
} else {
if ($body =~ m{ ^https?:// }x ) {
$body = $self->process_url($body, $message);
return $body if ($body =~ / ^$message->{who}: /x);
} else {
$body =~ s//\n/g;
}

my $response = $self->process_message($message, $body);
$response = $self->upload_output($response) if (length $response > 500);

Expand Down
15 changes: 11 additions & 4 deletions benchable.pl
Expand Up @@ -32,20 +32,27 @@ package Benchable;
sub process_message {
my ($self, $message, $body) = @_;

my $response = '';
my $msg_response = '';

if ($body =~ /^ \s* (\S+) \s+ (.+) /xu) {
my @commits = split(',', $1);
my $code = $2;

my ($succeeded, $code_response) = $self->process_code($code);
if ($succeeded) {
$code = $code_response;
} else {
return $code_response;
}

my $filename = $self->write_code($code);

my %times;
for my $commit (@commits) {
# convert to real ids so we can look up the builds
my $full_commit = $self->to_full_commit($commit);
unless (defined $full_commit) {
$response .= "Cannot find revision:$commit ";
$msg_response .= "Cannot find revision:$commit ";
next;
}

Expand All @@ -61,12 +68,12 @@ sub process_message {
chdir $old_dir;
}

$response .= join(' ', map { "$_=$times{$_}" } @commits);
$msg_response .= join(' ', map { "$_=$times{$_}" } @commits);
} else {
return help();
}

return $response;
return $msg_response;
}

sub help {
Expand Down
7 changes: 7 additions & 0 deletions bisectable.pl
Expand Up @@ -51,6 +51,13 @@ sub process_message {
my $bad = $2 // $3 // 'HEAD';
my $code = $5;

my ($succeeded, $code_response) = $self->process_code($code);
if ($succeeded) {
$code = $code_response;
} else {
return $code_response;
}

# convert to real ids so we can look up the builds
my $full_good = $self->to_full_commit($good);
return "Cannot find 'good' revision" unless defined $full_good;
Expand Down
19 changes: 13 additions & 6 deletions committable.pl
Expand Up @@ -31,19 +31,26 @@ package Committable;
sub process_message {
my ($self, $message, $body) = @_;

my $response = '';
my $msg_response = '';

if ($body =~ /^ \s* (\S+) \s+ (.+) /xu) {
my @commits = split(',', $1);
my $code = $2;

my ($succeeded, $code_response) = $self->process_code($code);
if ($succeeded) {
$code = $code_response;
} else {
return $code_response;
}

my $filename = $self->write_code($code);

for my $commit (@commits) {
# convert to real ids so we can look up the builds
my $full_commit = $self->to_full_commit($commit);
unless (defined $full_commit) {
$response .= "Cannot find revision:$commit ";
$msg_response .= "Cannot find revision:$commit ";
next;
}

Expand All @@ -53,14 +60,14 @@ sub process_message {
chdir $old_dir;
$out =~ s/\n//g if (defined $out);

$response .= "$commit: " . ($out // '') . " ";
$response .= " exit code = $exit" if ($exit != 0);
$msg_response .= "$commit: " . ($out // '') . " ";
$msg_response .= " exit code = $exit" if ($exit != 0);
}
} else {
$response = help();
$msg_response = help();
}

return $response;
return $msg_response;
}

sub help {
Expand Down

0 comments on commit be6da9e

Please sign in to comment.