Skip to content

Commit

Permalink
Handle GitHub API Redirects
Browse files Browse the repository at this point in the history
The API docs say any request can result in a redirect. Not handling this made us fail handling a couple of modules in the eco
  • Loading branch information
zoffixznet committed Nov 8, 2015
1 parent 01bb818 commit ae2dd75
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions web/lib/P6Project/Hosts/Github.pm
Expand Up @@ -57,13 +57,24 @@ sub get_api {
if ($call) {
$url .= $call;
}
my $tx = $self->p6p->ua->get($url, {Authorization => "token $github_token"});
if (! $tx->success ) {
my $error = $self->_format_error($tx->error);
$self->p6p->stats->error("Error for project $project->{name} : could not get $url: $error");
return;

FETCH_URL: {
my $tx = $self->p6p->ua->get($url, {Authorization => "token $github_token"});
if (! $tx->success ) {
my $error = $self->_format_error($tx->error);
$self->p6p->stats->error("Error for project $project->{name} : could not get $url: $error");
return;
}

my $res = $tx->res->json;
do { $url = $res->{url}; redo FETCH_URL; }
if ref $res eq 'HASH'
and $res->{message}
and $res->{message} eq 'Moved Permanently'
and $url ne $res->{url};

return $res;
}
return $tx->res->json;
}

sub file_url {
Expand Down

0 comments on commit ae2dd75

Please sign in to comment.