Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fetch travis file contents
  • Loading branch information
zoffixznet committed Jul 29, 2018
1 parent 9a94f69 commit 866b0af
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/ModulesPerl6/DbBuilder/Dist/PostProcessor/p05DataFetcher.pm
Expand Up @@ -22,31 +22,31 @@ use feature 'state';
sub process {
my $self = shift;

$self->_fetch_content_for_first_readme;
$self->__fetch_file(sub {$_[0]->{name} =~ /^README/i }, 'README');
$self->__fetch_file(sub {$_[0]->{name} eq '.travis.yml'}, 'README');

This comment has been minimized.

Copy link
@MasterDuke17

MasterDuke17 Jul 29, 2018

It looks like the 'README' was copied, but the second should be '.travis.yml'?

This comment has been minimized.

Copy link
@zoffixznet

zoffixznet Jul 29, 2018

Author

Thanks. Fixed in 4c03426399


return 1;
}

sub _fetch_content_for_first_readme {
my $self = shift;
sub __fetch_file {
my ($self, $file_grep, $error_name) = @_;
my $dist = $self->_dist;

my ($readme) = grep $_->{name} =~ /^README/i,
my ($file) = grep {$file_grep->($_)}
($dist->{_builder}{files} || [])->@*
or return;

state $token = trim path($ENV{MODULES_PERL6_GITHUB_TOKEN_FILE})->slurp;
my $content = eval {
my $res_json = Mojo::UserAgent->new( max_redirects => 5 )
->get( $readme->{url} => {
->get( $file->{url} => {
Authorization => "token $token"
})->result->json;
defined $res_json->{content} or die $res_json->{message};
$res_json;
};
if ($@) {
log error => "ERROR fetching README content: $@";
$readme->{error} = "$@";
$file->{error} = "$@";
return;
}

Expand All @@ -58,12 +58,11 @@ sub _fetch_content_for_first_readme {

# Possible encodings are 'utf-8' and 'base64', per
# https://developer.github.com/v3/git/blobs/#parameters
$readme->{content} = $content->{encoding} eq 'base64'
$file->{content} = $content->{encoding} eq 'base64'
? (b64_decode $content->{content})
: $content->{content};
}

1;

__END__

0 comments on commit 866b0af

Please sign in to comment.