Changeset 49aca65 in lab.git for Dev/github


Ignore:
Timestamp:
Aug 19, 2013 10:58:01 AM (11 years ago)
Author:
Ken-ichi Mito <mitty@…>
Branches:
master
Children:
d51047d
Parents:
55d0513
Message:

save issue as json and pacth files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/github/GitHubBackup.pm

    r55d0513 r49aca65  
    77use LWP::UserAgent; 
    88use JSON; 
    9 my $ua = LWP::UserAgent->new; 
    10 my $json = JSON->new->utf8->indent; 
    119 
    1210sub json_api { 
    1311    my $url = shift; 
     12     
     13    my $ua = LWP::UserAgent->new; 
     14    my $json = JSON->new->utf8->indent; 
    1415     
    1516    my $res = $ua->get( 
     
    150151use File::Spec; 
    151152use File::Path qw(mkpath); 
     153use LWP::UserAgent; 
     154use JSON; 
     155 
    152156 
    153157sub new { 
     
    266270    my $self = shift; 
    267271     
    268     $self->issues; 
     272    my $ua = LWP::UserAgent->new; 
     273    my $json = JSON->new->utf8->indent; 
     274     
     275    my $dir = $self->directory . '.issues'; 
     276    mkpath $dir unless (-d $dir); 
     277    local $CWD = $dir; 
     278    foreach my $issue (@{$self->issues}) { 
     279        my $number = $issue->{number}; 
     280        print "save issue/$number\n"; 
     281         
     282        open my $fh, ">$number.json"; 
     283        print $fh $json->encode($issue); 
     284        close $fh; 
     285         
     286        if (exists $issue->{pull_request}{patch_url}) { 
     287            $ua->mirror($issue->{pull_request}{patch_url} => "$number.patch"); 
     288        } 
     289    } 
     290     
     291    return $self; 
    269292} 
    270293 
Note: See TracChangeset for help on using the changeset viewer.