line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Github::Backup; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
54887
|
use strict; |
|
5
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
115
|
|
4
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
119
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
18
|
use Carp qw(croak); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
336
|
|
7
|
5
|
|
|
5
|
|
2588
|
use Data::Dumper; |
|
5
|
|
|
|
|
39461
|
|
|
5
|
|
|
|
|
288
|
|
8
|
5
|
|
|
5
|
|
2118
|
use Git::Repository; |
|
5
|
|
|
|
|
184240
|
|
|
5
|
|
|
|
|
20
|
|
9
|
5
|
|
|
5
|
|
2229
|
use File::Copy; |
|
5
|
|
|
|
|
17472
|
|
|
5
|
|
|
|
|
237
|
|
10
|
5
|
|
|
5
|
|
27
|
use File::Path; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
241
|
|
11
|
5
|
|
|
5
|
|
2464
|
use JSON; |
|
5
|
|
|
|
|
39022
|
|
|
5
|
|
|
|
|
25
|
|
12
|
5
|
|
|
5
|
|
2963
|
use LWP::UserAgent; |
|
5
|
|
|
|
|
171552
|
|
|
5
|
|
|
|
|
143
|
|
13
|
5
|
|
|
5
|
|
2108
|
use Moo; |
|
5
|
|
|
|
|
30760
|
|
|
5
|
|
|
|
|
21
|
|
14
|
5
|
|
|
5
|
|
7641
|
use Pithub; |
|
5
|
|
|
|
|
513730
|
|
|
5
|
|
|
|
|
168
|
|
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
34
|
use namespace::clean; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
38
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# external |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has api_user => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
has _clean => ( |
26
|
|
|
|
|
|
|
# used to clean up test backup directories |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
has dir => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
has forks => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
has token => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
has proxy => ( |
39
|
|
|
|
|
|
|
is => 'rw', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
has user => ( |
42
|
|
|
|
|
|
|
is => 'rw', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# internal |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has gh => ( |
48
|
|
|
|
|
|
|
# Pithub object |
49
|
|
|
|
|
|
|
is => 'rw', |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
has stg => ( |
52
|
|
|
|
|
|
|
# staging dir |
53
|
|
|
|
|
|
|
is => 'rw', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub BUILD { |
57
|
6
|
|
|
6
|
0
|
7987
|
my ($self) = @_; |
58
|
|
|
|
|
|
|
|
59
|
6
|
100
|
|
|
|
24
|
if (! $self->token){ |
60
|
2
|
50
|
|
|
|
6
|
$self->token($ENV{GITHUB_TOKEN}) if $ENV{GITHUB_TOKEN}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
21
|
for ($self->api_user, $self->token, $self->dir){ |
64
|
13
|
100
|
|
|
|
23
|
if (! $_){ |
65
|
4
|
|
|
|
|
463
|
croak "When instantiating an object, the 'api_user', 'token' and " . |
66
|
|
|
|
|
|
|
"'dir' parameters are mandatory...\n"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
14
|
my $ua = LWP::UserAgent->new; |
71
|
|
|
|
|
|
|
|
72
|
2
|
100
|
|
|
|
4577
|
if ($self->proxy){ |
73
|
1
|
|
|
|
|
8
|
$ENV{http_proxy} = $self->proxy; |
74
|
1
|
|
|
|
|
5
|
$ENV{https_proxy} = $self->proxy; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
4
|
$ua->env_proxy; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
34522
|
my $gh = Pithub->new( |
80
|
|
|
|
|
|
|
ua => $ua, |
81
|
|
|
|
|
|
|
user => $self->api_user, |
82
|
|
|
|
|
|
|
token => $self->token |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
16659
|
$self->stg($self->dir . '.stg'); |
86
|
2
|
|
|
|
|
6
|
$self->gh($gh); |
87
|
|
|
|
|
|
|
|
88
|
2
|
50
|
|
|
|
16
|
$self->user($self->api_user) if ! defined $self->user; |
89
|
|
|
|
|
|
|
|
90
|
2
|
50
|
|
|
|
70
|
if (-d $self->stg){ |
91
|
0
|
0
|
|
|
|
0
|
rmtree $self->stg or die "can't remove the old staging directory...$!"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
2
|
50
|
|
|
|
149
|
mkdir $self->stg or die "can't create the backup staging directory...$!\n"; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
sub repos { |
98
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
my $repo_list = $self->gh->repos->list(user => $self->user); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
my @repos; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
while (my $repo = $repo_list->next){ |
105
|
0
|
|
|
|
|
0
|
push @repos, $repo; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
for my $repo (@repos){ |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
my $stg = $self->stg . "/$repo->{name}"; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
0
|
if (! $self->forks){ |
113
|
0
|
0
|
|
|
|
0
|
if (! exists $repo->{parent}){ |
114
|
|
|
|
|
|
|
Git::Repository->run( |
115
|
0
|
|
|
|
|
0
|
clone => $repo->{clone_url} => $stg, |
116
|
|
|
|
|
|
|
{quiet => 1} |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
|
|
|
|
|
|
Git::Repository->run( |
122
|
0
|
|
|
|
|
0
|
clone => $repo->{clone_url} => $stg, |
123
|
|
|
|
|
|
|
{ quiet => 1 } |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
sub issues { |
129
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
0
|
mkdir $self->stg . "/issues" or die "can't create the 'issues' dir: $!"; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
my $repo_list = $self->gh->repos->list(user => $self->user); |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
while (my $repo = $repo_list->next){ |
136
|
|
|
|
|
|
|
my $issue_list = $self->gh->issues->list( |
137
|
|
|
|
|
|
|
user => $self->user, |
138
|
|
|
|
|
|
|
repo => $repo->{name} |
139
|
0
|
|
|
|
|
0
|
); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
0
|
my $issue_dir = $self->stg . "/issues/$repo->{name}"; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
0
|
my $dir_created = 0; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
0
|
while (my $issue = $issue_list->next){ |
147
|
0
|
0
|
|
|
|
0
|
if (! $dir_created) { |
148
|
0
|
0
|
|
|
|
0
|
mkdir $issue_dir or die $!; |
149
|
0
|
|
|
|
|
0
|
$dir_created = 1; |
150
|
|
|
|
|
|
|
} |
151
|
0
|
0
|
|
|
|
0
|
open my $fh, '>', "$issue_dir/$issue->{id}" |
152
|
|
|
|
|
|
|
or die "can't create the issue file"; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
0
|
print $fh encode_json $issue; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
sub DESTROY { |
159
|
6
|
|
|
6
|
|
2991
|
my $self = shift; |
160
|
|
|
|
|
|
|
|
161
|
6
|
50
|
66
|
|
|
112
|
if ($self->dir && -d $self->dir) { |
162
|
0
|
0
|
|
|
|
0
|
rmtree $self->dir or die "can't remove the old backup directory: $!"; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
6
|
100
|
66
|
|
|
49
|
if ($self->stg && -d $self->stg) { |
166
|
2
|
50
|
|
|
|
18
|
move $self->stg, |
167
|
|
|
|
|
|
|
$self->dir or die "can't rename the staging directory: $!"; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
6
|
100
|
100
|
|
|
251
|
if ($self->dir && -d $self->dir && $self->_clean) { |
|
|
|
100
|
|
|
|
|
171
|
|
|
|
|
|
|
# we're in testing mode, clean everything up |
172
|
1
|
50
|
|
|
|
470
|
rmtree $self->dir |
173
|
|
|
|
|
|
|
or die "can't remove the test backup directory...$!"; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
__END__ |