Changeset 19233f5 in lab.git for Dev/github/GitHubBackup.pm
- Timestamp:
- Aug 18, 2013 3:21:49 AM (11 years ago)
- Branches:
- master
- Children:
- b8d7413
- Parents:
- 6a2e5f1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/github/GitHubBackup.pm
r6a2e5f1 r19233f5 22 22 } 23 23 24 24 25 package GitHubBackup; 25 26 use base qw(Class::Accessor::Fast); … … 42 43 43 44 my $args = (ref $_[0] eq 'HASH') ? $_[0] : {@_}; 45 if (! $args->{directory}) { 46 $args->{directory} = "."; 47 } 48 44 49 return $class->SUPER::new($args); 45 50 } … … 47 52 sub repos { 48 53 my $self = shift; 54 return $self->{repos} if ($self->{repos}); 49 55 50 56 my $account = $self->account or croak "account is not set"; 51 57 if (my $repository = $self->repository) { 52 58 $self->{repos} = [ 53 GitHubBackup::Repository->new( 54 {full_name => "$account/$repository"} 55 ) 59 GitHubBackup::Repository->new({ 60 __super => $self, 61 full_name => "$account/$repository", 62 }) 56 63 ]; 57 64 … … 75 82 push @{$self->{repos}}, 76 83 GitHubBackup::Repository->new({ 84 __super => $self, 77 85 full_name => $repos->{full_name}, 78 86 clone_url => $repos->{clone_url}, … … 92 100 use utf8; 93 101 use Carp qw(croak); 102 use Git::Repository; 103 use File::chdir; 104 105 sub new { 106 my $class = shift; 107 my $args = shift; 108 109 if (! exists $args->{clone_url}) { 110 my $result = utils::json_api('/repos/' . $args->{full_name}); 111 $args->{clone_url} = $result->{clone_url}; 112 } 113 114 return $class->SUPER::new($args); 115 } 116 117 sub clone_git { 118 my $self = shift; 119 120 my $dir = $self->{__super}->directory .'/'. $self->{full_name}; 121 if (-d "$dir") { 122 local $CWD = $dir; 123 print "fetch ", $self->{full_name}, "\n"; 124 Git::Repository->run(fetch => '--all'); 125 return $self; 126 } 127 128 print "clone ", $self->{full_name}, "\n"; 129 Git::Repository->run(clone => '--mirror' => $self->{clone_url} => $dir); 130 return $self; 131 } 132 133 sub set_forks { 134 my $self = shift; 135 } 136 137 sub clone_wiki { 138 my $self = shift; 139 } 140 141 sub save_issues { 142 my $self = shift; 143 } 94 144 95 145
Note: See TracChangeset
for help on using the changeset viewer.