Skip to content

Instantly share code, notes, and snippets.

@masartz
Created January 12, 2016 15:44
Show Gist options
  • Save masartz/96077f63e56dc820455b to your computer and use it in GitHub Desktop.
Save masartz/96077f63e56dc820455b to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use File::Path;
use File::Slurp;
use JSON;
my $user = $ARGV[0];
my $repos = $ARGV[1];
my $token = $ARGV[2];
my $count = $ARGV[3];
my $body_format = "https://api.github.com/repos/$user/$repos/issues/%d";
my $comment_format = $body_format . '/comments';
for my $issue_no ( 1..$count){
my $dir = sprintf 'issue_%02d' , $issue_no;
File::Path::mkpath($dir);
my $body_url = sprintf $body_format , $issue_no;
my $body_ret = `curl -u "$user:$token" $body_url`;
File::Slurp::write_file( "$dir/body.json" , $body_ret );
my $comment_url = sprintf $comment_format , $issue_no;
my $comment_ret = `curl -u "$user:$token" $comment_url`;
File::Slurp::write_file( "$dir/comment.json" , $comment_ret );
get_image( $dir , $comment_ret);
}
sub get_image{
my ($dir , $response) = @_;
my $parsed_response = JSON::decode_json $response;
for my $element ( @{$parsed_response} ){
if ($element->{'body'} =~ /\[(.+)\]\((.+)\)/ ){
my $image = `curl $2`;
my $image_file = $1;
$image_file =~ s/.+LGTM.+/LGTM/;
File::Slurp::write_file( "$dir/$image_file.jpg" , $image );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment