| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | package Dist::Zilla::Plugin::CPAN::Mini::Inject::REST; | ||
| 4 | |||
| 5 | our $VERSION = '0.004'; | ||
| 6 | |||
| 7 | use Moose; | ||
| 8 | use Data::Dump; | ||
| 9 | extends 'CPAN::Mini::Inject::REST::Client::API'; | ||
| 10 | |||
| 11 | with 'Dist::Zilla::Role::Releaser'; | ||
| 12 | |||
| 13 | has '+port' => ( default => 80 ); | ||
| 14 | has '+protocol' => ( default => 'http' ); | ||
| 15 | |||
| 16 | sub release { | ||
| 17 | my ($self, $archive) = @_; | ||
| 18 | |||
| 19 | if($ENV{ALREADY_UPLOADED_PRETEND_THIS_HAPPENED_ALREADY}) | ||
| 20 | { | ||
| 21 | # sometimes the CPAN::Mini::Inject::REST reports an error | ||
| 22 | # despite successfully uploading and indexing a distribution. | ||
| 23 | # this leaves us in an awkward state as we can't re-upload it | ||
| 24 | # and we need this step to pass to get the rest of the release | ||
| 25 | # tasks accomplished. | ||
| 26 | # NOTE: this often a 504 because the timeouts on the frontend | ||
| 27 | # nginx are too low. Since the server does the whole indexing | ||
| 28 | # during the processing of the REST call itself this can take a | ||
| 29 | # while. | ||
| 30 | $self->log("Pretending we succesfully uploaded $archive"); | ||
| 31 | return; | ||
| 32 | } | ||
| 33 | if($self->host =~ qr|//|) | ||
| 34 | { | ||
| 35 | # stop a common goof that was being reported as a 500. | ||
| 36 | # despite not actually reaching a server. | ||
| 37 | $self->log_fatal(sprintf "host looks like a url (%s), please change it to a hostname.", $self->host); | ||
| 38 | } | ||
| 39 | $self->log_debug(sprintf "Sending %s to %s://%s:%d", $archive, $self->protocol, $self->host, $self->port); | ||
| 40 | |||
| 41 | my ($code, $result) = $self->post( | ||
| 42 | qq(repository/$archive) => { | ||
| 43 | file => ["$archive"] | ||
| 44 | } | ||
| 45 | ); | ||
| 46 | |||
| 47 | if ($code >= 500) { | ||
| 48 | # FIXME - does it give us info? | ||
| 49 | $self->log_fatal("$code: Server error"); | ||
| 50 | } | ||
| 51 | elsif ($code >= 400) { | ||
| 52 | my $error = ref $result ? $result->{error} : $result; | ||
| 53 | |||
| 54 | $error = pp $error if ref $error; | ||
| 55 | |||
| 56 | $self->log_fatal("$code: Client error: $error"); | ||
| 57 | } | ||
| 58 | elsif ($code >= 300) { | ||
| 59 | $self->log_fatal("Unexpected $code that wasn't followed"); | ||
| 60 | } | ||
| 61 | else { | ||
| 62 | $self->log("Successfully indexed $archive"); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | 1; | ||
| 67 | |||
| 68 | __END__ |