line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Github::Fork::Parent; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
579790
|
use 5.006; |
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
42
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
116
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Github::Fork::Parent - Perl module to determine which repository stands in a root of GitHub forking hierarchy. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 1.0 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $parent_url = github_parent('git://github.com/chorny/plagger.git'); |
23
|
|
|
|
|
|
|
#returns https://github.com/miyagawa/plagger |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 FUNCTIONS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 github_parent |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Takes link to repository (git://, git@ or http://) and returns http link to root repository. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 github_parent_author |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Takes link to repository (git://, git@ or http://) and returns owner of root repository. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
|
2099
|
use JSON; |
|
2
|
|
|
|
|
22630
|
|
|
2
|
|
|
|
|
10
|
|
38
|
|
|
|
|
|
|
#use YAML::Tiny 1.40; |
39
|
2
|
|
|
2
|
|
884
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
39113
|
|
|
2
|
|
|
|
|
66
|
|
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
2
|
|
17
|
use Exporter 'import'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
828
|
|
42
|
|
|
|
|
|
|
our @EXPORT = qw(github_parent github_parent_author); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_repo_data { |
45
|
4
|
|
|
4
|
0
|
13
|
my ($author,$project)=@_; |
46
|
|
|
|
|
|
|
#my $url = "http://github.com/api/v2/yaml/repos/show/$author/$project/network"; |
47
|
4
|
|
|
|
|
16
|
my $url = "https://api.github.com/repos/$author/$project"; |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
36
|
my $ua=LWP::UserAgent->new(); |
50
|
4
|
|
|
|
|
1037
|
$ua->timeout(50); |
51
|
4
|
|
|
|
|
68
|
my $response = $ua->get($url); |
52
|
4
|
50
|
|
|
|
1460207
|
if ($response->is_success) { |
53
|
4
|
|
|
|
|
53
|
my $yaml = $response->content(); |
54
|
4
|
|
|
|
|
1051
|
return $yaml; |
55
|
|
|
|
|
|
|
} else { |
56
|
0
|
0
|
|
|
|
0
|
if ($response->code eq '404') { |
57
|
0
|
|
|
|
|
0
|
return undef; |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
0
|
die "Could not GET data (".$response->status_line.")"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub parse_github_links { |
65
|
10
|
|
|
10
|
0
|
4677
|
my $link=shift; |
66
|
10
|
|
|
|
|
297
|
$link =~ s/\.git$//; #github does not allow repositories ending in .git, so we can safely remove extension |
67
|
10
|
50
|
|
|
|
76
|
if ($link=~m{^ |
68
|
|
|
|
|
|
|
(?:\Qgit://github.com/\E|git\@github\.com:|https?://github\.com/) |
69
|
|
|
|
|
|
|
([^/]+)/([^/]+) #repository name can contain dots |
70
|
|
|
|
|
|
|
$ }x |
71
|
|
|
|
|
|
|
) { |
72
|
10
|
|
|
|
|
53
|
return ($1,$2); |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
0
|
return (undef,undef); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub github_parent { |
80
|
2
|
|
|
2
|
1
|
316262
|
my $link=shift; |
81
|
2
|
|
|
|
|
9
|
my ($author,$project)=parse_github_links($link); |
82
|
2
|
50
|
|
|
|
8
|
return $link unless $author; |
83
|
2
|
|
|
|
|
6
|
my $yaml_content=get_repo_data($author,$project); |
84
|
2
|
50
|
|
|
|
22
|
if ($yaml_content) { |
85
|
|
|
|
|
|
|
#my $yaml=YAML::Tiny->read_string($yaml_content) or die; |
86
|
2
|
|
|
|
|
338
|
my $yaml=decode_json($yaml_content); |
87
|
2
|
|
|
|
|
8
|
my $source_url=$yaml->{source}{html_url}; |
88
|
2
|
50
|
|
|
|
8
|
die unless $source_url; |
89
|
2
|
|
|
|
|
56
|
return $source_url; |
90
|
|
|
|
|
|
|
} else { |
91
|
0
|
|
|
|
|
0
|
die "No content for $author/$project"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub github_parent_author { |
96
|
|
|
|
|
|
|
#my $link=shift; |
97
|
|
|
|
|
|
|
#my $link1=github_parent($link); |
98
|
|
|
|
|
|
|
#my ($author,$project)=parse_github_links($link1); |
99
|
|
|
|
|
|
|
#die "Cannot get author from '$link1'" unless $author; |
100
|
|
|
|
|
|
|
#return $author; |
101
|
2
|
|
|
2
|
1
|
5
|
my $link=shift; |
102
|
2
|
|
|
|
|
9
|
my ($author,$project)=parse_github_links($link); |
103
|
2
|
50
|
|
|
|
9
|
return $link unless $author; |
104
|
2
|
|
|
|
|
9
|
my $yaml_content=get_repo_data($author,$project); |
105
|
2
|
50
|
|
|
|
8
|
if ($yaml_content) { |
106
|
|
|
|
|
|
|
#my $yaml=YAML::Tiny->read_string($yaml_content) or die; |
107
|
2
|
|
|
|
|
245
|
my $yaml=decode_json($yaml_content); |
108
|
2
|
100
|
|
|
|
45
|
return $author unless $yaml->{'fork'}; |
109
|
1
|
|
|
|
|
10
|
my $source=$yaml->{source}{owner}{login}; |
110
|
1
|
50
|
|
|
|
4
|
die "No login in YAML for $link" unless $source; |
111
|
1
|
|
|
|
|
41
|
return $source; |
112
|
|
|
|
|
|
|
} else { |
113
|
0
|
|
|
|
|
|
die "No content"; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Alexandr Ciornii, C<< >> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 BUGS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
124
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
125
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SUPPORT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
perldoc Github::Fork::Parent |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
You can also look for information at: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * CPAN Ratings |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * Search CPAN |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SEE ALSO |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Net::GitHub |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Copyright 2009-2017 Alexandr Ciornii. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
169
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
170
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; # End of Github::Fork::Parent |