From 49aca65932305edcb650e74db439092f1ffa4416 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Mon, 19 Aug 2013 10:58:01 +0900 Subject: [PATCH] save issue as json and pacth files --- Dev/github/GitHubBackup.pm | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) 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 { -- 1.7.9.5