sub clone_git {
my $self = shift;
- my $dir = $self->directory;
+ my $dir = $self->directory . '.git';
if (-d "$dir") {
local $CWD = $dir;
print "fetch ", $dir, "\n";
return $self;
}
+sub get_forks {
+ my $self = shift;
+ return $self->{forks} if ($self->{forks});
+
+ my $page = 1;
+ while (1) {
+ my $result = utils::json_api("/repos/" . $self->{full_name} . "/forks?per_page=100&page=$page");
+ if (ref($result) eq 'ARRAY' && scalar @$result > 0) {
+ push @{$self->{forks}}, @$result;
+ $page++;
+
+ next;
+ }
+ last;
+ }
+
+ return $self;
+}
+
sub set_forks {
my $self = shift;
+
+ $self->get_forks;
+
+ my $dir = $self->directory . '.git';
+ local $CWD = $dir;
+
+ my $remotes = Git::Repository->run(branch => '--remotes');
+ foreach my $fork (@{$self->{forks}}) {
+ if ($remotes =~ /$fork->{full_name}/) {
+ print "skip ", $fork->{full_name}, "\n";
+ next;
+ }
+ print "add ", $fork->{full_name}, "\n";
+ Git::Repository->run(remote => add => $fork->{full_name} => $fork->{clone_url});
+ }
+
+ print "fetch ", $dir, "\n";
+ Git::Repository->run(fetch => '--all');
+
+ return $self;
}
sub clone_wiki {