From 55d0513b04f2240cb047566e7fd121df89ea499a Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Mon, 19 Aug 2013 10:21:00 +0900 Subject: [PATCH] utils::get with %parameters --- Dev/github/GitHubBackup.pm | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Dev/github/GitHubBackup.pm b/Dev/github/GitHubBackup.pm index 3d57a0f..7cc05d5 100644 --- a/Dev/github/GitHubBackup.pm +++ b/Dev/github/GitHubBackup.pm @@ -23,11 +23,17 @@ sub json_api { sub get { my $url = shift; + my %parameters = @_; + + my $parameters = ''; + while (my($key, $value) = each %parameters) { + $parameters .= "&$key=$value"; + } my $page = 1; my $data; while(1) { - my $result = json_api("$url?per_page=100&page=$page"); + my $result = json_api("$url?per_page=100&page=$page$parameters"); if (ref($result) eq 'ARRAY' && scalar @$result > 0) { push @$data, @$result; $page++; @@ -197,26 +203,24 @@ sub clone_git { return $self; } -sub get_forks { +sub forks { my $self = shift; return $self->{forks} if ($self->{forks}); $self->{forks} = utils::get("/repos/" . $self->{full_name} . "/forks"); - return $self; + return $self->{forks}; } sub set_forks { my $self = shift; - $self->get_forks; - my $dir = $self->directory . '.git'; local $CWD = $dir; my $remotes = Git::Repository->run(branch => '--remotes'); my @fetch; - foreach my $fork (@{$self->{forks}}) { + foreach my $fork (@{$self->forks}) { if ($remotes =~ /$fork->{full_name}/) { print "skip ", $fork->{full_name}, "\n"; next; @@ -245,8 +249,23 @@ sub clone_wiki { return $self; } +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'); + + if ($open) { push @{$self->{issues}}, @$open } + if ($closed) { push @{$self->{issues}}, @$closed } + + return $self->{issues}; +} + sub save_issues { my $self = shift; + + $self->issues; } sub backup { -- 1.7.9.5