From: Ken-ichi Mito Date: Wed, 21 Aug 2013 01:47:41 +0000 (+0900) Subject: change GitHubBackup::Repository data structure X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=c5b427c77f031699a95237c7ff217c1156cdb075;p=lab.git change GitHubBackup::Repository data structure * keep original structure from api --- diff --git a/Dev/github/GitHubBackup.pm b/Dev/github/GitHubBackup.pm index a821840..73cf1d4 100644 --- a/Dev/github/GitHubBackup.pm +++ b/Dev/github/GitHubBackup.pm @@ -106,24 +106,19 @@ sub repos { $self->{repos} = []; my $account = $self->account or croak "account is not set"; + my $result; if (my $repository = $self->repository) { - $self->{repos} = [ - GitHubBackup::Repository->new({ - directory => sub {$self->directory}, - full_name => "$account/$repository", - }) - ]; - - return $self->{repos}; + $result = [ utils::json_api("/repos/$account/$repository") ]; + } + else { + $result = utils::get("/users/$account/repos"); } - my $result = utils::get("/users/$account/repos"); foreach my $repos (@$result) { push @{$self->{repos}}, GitHubBackup::Repository->new({ directory => sub {$self->directory}, - full_name => $repos->{full_name}, - clone_url => $repos->{clone_url}, + repos => $repos, }) ; } @@ -160,18 +155,21 @@ sub new { my $class = shift; my $args = shift; - if (! exists $args->{clone_url}) { - my $result = utils::json_api('/repos/' . $args->{full_name}); - $args->{clone_url} = $result->{clone_url}; - } - return bless $args, $class; } +sub clone_url { + return (shift)->{repos}{clone_url}; +} + +sub full_name { + return (shift)->{repos}{full_name}; +} + sub directory { my $self = shift; - my $path = $self->{full_name}; + my $path = $self->full_name; if (my $base = $self->{directory}->()) { $path = File::Spec->catfile($base, $path); } @@ -202,7 +200,7 @@ sub clone_git { my $self = shift; my $dir = $self->directory . '.git'; - my $url = $self->{clone_url}; + my $url = $self->clone_url; $self->sync($url => $dir); @@ -213,7 +211,7 @@ sub forks { my $self = shift; return $self->{forks} if ($self->{forks}); - $self->{forks} = utils::get("/repos/" . $self->{full_name} . "/forks"); + $self->{forks} = utils::get("/repos/" . $self->full_name . "/forks"); return $self->{forks}; } @@ -248,7 +246,7 @@ sub clone_wiki { my $self = shift; my $dir = $self->directory . '.wiki.git'; - my $url = 'https://github.com/' . $self->{full_name} . '.wiki.git'; + my $url = 'https://github.com/' . $self->full_name . '.wiki.git'; $self->sync($url => $dir); @@ -259,8 +257,8 @@ sub issues { my $self = shift; return $self->{issues} if ($self->{issues}); - my $open = utils::get("/repos/" . $self->{full_name} . "/issues"); - my $closed = utils::get("/repos/" . $self->{full_name} . "/issues", state => 'closed'); + my $open = utils::get("/repos/" . $self->full_name . "/issues"); + my $closed = utils::get("/repos/" . $self->full_name . "/issues", state => 'closed'); if ($open) { push @{$self->{issues}}, @$open } if ($closed) { push @{$self->{issues}}, @$closed }