From: Ken-ichi Mito Date: Mon, 19 Aug 2013 01:58:01 +0000 (+0900) Subject: save issue as json and pacth files X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=49aca65932305edcb650e74db439092f1ffa4416;p=lab.git save issue as json and pacth files --- diff --git a/Dev/github/GitHubBackup.pm b/Dev/github/GitHubBackup.pm index 7cc05d5..d9d35a3 100644 --- a/Dev/github/GitHubBackup.pm +++ b/Dev/github/GitHubBackup.pm @@ -6,12 +6,13 @@ use Carp qw(croak); use LWP::UserAgent; use JSON; -my $ua = LWP::UserAgent->new; -my $json = JSON->new->utf8->indent; sub json_api { my $url = shift; + my $ua = LWP::UserAgent->new; + my $json = JSON->new->utf8->indent; + my $res = $ua->get( "https://api.github.com$url" ); @@ -149,6 +150,9 @@ use Git::Repository; use File::chdir; use File::Spec; use File::Path qw(mkpath); +use LWP::UserAgent; +use JSON; + sub new { my $class = shift; @@ -265,7 +269,26 @@ sub issues { sub save_issues { my $self = shift; - $self->issues; + my $ua = LWP::UserAgent->new; + my $json = JSON->new->utf8->indent; + + my $dir = $self->directory . '.issues'; + mkpath $dir unless (-d $dir); + local $CWD = $dir; + foreach my $issue (@{$self->issues}) { + my $number = $issue->{number}; + print "save issue/$number\n"; + + open my $fh, ">$number.json"; + print $fh $json->encode($issue); + close $fh; + + if (exists $issue->{pull_request}{patch_url}) { + $ua->mirror($issue->{pull_request}{patch_url} => "$number.patch"); + } + } + + return $self; } sub backup {