From 19df4003ce0a35bb63b6f9d0e2f5c6e371701b82 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Sun, 18 Aug 2013 04:55:43 +0900 Subject: [PATCH] remake accessors and create backup() method * repository list will flush with account() and repository() * backup() do backup --- Dev/github/GitHubBackup.pm | 50 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/Dev/github/GitHubBackup.pm b/Dev/github/GitHubBackup.pm index dc147d4..34e40e6 100644 --- a/Dev/github/GitHubBackup.pm +++ b/Dev/github/GitHubBackup.pm @@ -32,8 +32,6 @@ use Carp qw(croak); __PACKAGE__->mk_accessors( qw( directory - account - repository )); @@ -49,6 +47,30 @@ sub new { return $class->SUPER::new($args); } +sub account { + my $self = shift; + my $args = shift; + + if (defined $args) { + $self->{repos} = undef; + $self->{account} = $args; + } + + return $self->{account}; +} + +sub repository { + my $self = shift; + my $args = shift; + + if (defined $args) { + $self->{repos} = undef; + $self->{repository} = $args; + } + + return $self->{repository}; +} + sub repos { my $self = shift; return $self->{repos} if ($self->{repos}); @@ -91,6 +113,16 @@ sub repos { return $self->{repos}; } +sub backup { + my $self = shift; + + foreach my $repos (@{$self->repos}) { + $repos->backup; + } + + return $self; +} + package GitHubBackup::Repository; use base qw(Class::Accessor::Fast); @@ -127,12 +159,12 @@ sub clone_git { my $dir = $self->directory .'/'. $self->{full_name}; if (-d "$dir") { local $CWD = $dir; - print "fetch ", $self->{full_name}, "\n"; + print "fetch ", $dir, "\n"; Git::Repository->run(fetch => '--all'); return $self; } - print "clone ", $self->{full_name}, "\n"; + print "clone ", $dir, "\n"; Git::Repository->run(clone => '--mirror' => $self->{clone_url} => $dir); return $self; } @@ -149,6 +181,16 @@ sub save_issues { my $self = shift; } +sub backup { + my $self = shift; + + $self->clone_git; + $self->set_forks; + $self->clone_wiki; + $self->save_issues; + + return $self; +} 1; -- 1.7.9.5