$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,
})
;
}
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);
}
my $self = shift;
my $dir = $self->directory . '.git';
- my $url = $self->{clone_url};
+ my $url = $self->clone_url;
$self->sync($url => $dir);
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};
}
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);
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 }