line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Github::Fork::Parent; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
562869
|
use 5.006; |
|
2
|
|
|
|
|
5
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
36
|
|
5
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
89
|
|
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.0'; |
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
|
|
1225
|
use JSON; |
|
2
|
|
|
|
|
20184
|
|
|
2
|
|
|
|
|
8
|
|
38
|
|
|
|
|
|
|
#use YAML::Tiny 1.40; |
39
|
2
|
|
|
2
|
|
855
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
32246
|
|
|
2
|
|
|
|
|
63
|
|
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
2
|
|
12
|
use Exporter 'import'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
804
|
|
42
|
|
|
|
|
|
|
our @EXPORT = qw(github_parent github_parent_author); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_repo_data { |
45
|
4
|
|
|
4
|
0
|
9
|
my ($author,$project)=@_; |
46
|
|
|
|
|
|
|
#my $url = "http://github.com/api/v2/yaml/repos/show/$author/$project/network"; |
47
|
4
|
|
|
|
|
15
|
my $url = "https://api.github.com/repos/$author/$project"; |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
36
|
my $ua=LWP::UserAgent->new(); |
50
|
4
|
|
|
|
|
747
|
$ua->timeout(50); |
51
|
4
|
|
|
|
|
47
|
my $response = $ua->get($url); |
52
|
4
|
50
|
|
|
|
1762909
|
if ($response->is_success) { |
53
|
4
|
|
|
|
|
58
|
my $yaml = $response->content(); |
54
|
4
|
|
|
|
|
237
|
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
|
3126
|
my $link=shift; |
66
|
10
|
|
|
|
|
36
|
$link =~ s/\.git$//; #github does not allow repositories ending in .git, so we can safely remove extension |
67
|
10
|
50
|
|
|
|
104
|
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
|
|
|
|
|
46
|
return ($1,$2); |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
0
|
return (undef,undef); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub github_parent { |
80
|
2
|
|
|
2
|
1
|
510891
|
my $link=shift; |
81
|
2
|
|
|
|
|
11
|
my ($author,$project)=parse_github_links($link); |
82
|
2
|
50
|
|
|
|
9
|
return $link unless $author; |
83
|
2
|
|
|
|
|
7
|
my $yaml_content=get_repo_data($author,$project); |
84
|
2
|
50
|
|
|
|
7
|
if ($yaml_content) { |
85
|
|
|
|
|
|
|
#my $yaml=YAML::Tiny->read_string($yaml_content) or die; |
86
|
2
|
|
|
|
|
295
|
my $yaml=decode_json($yaml_content); |
87
|
2
|
|
|
|
|
5
|
my $source_url=$yaml->{source}{html_url}; |
88
|
2
|
50
|
|
|
|
9
|
die unless $source_url; |
89
|
2
|
|
|
|
|
50
|
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
|
|
|
|
|
6
|
my ($author,$project)=parse_github_links($link); |
103
|
2
|
50
|
|
|
|
9
|
return $link unless $author; |
104
|
2
|
|
|
|
|
7
|
my $yaml_content=get_repo_data($author,$project); |
105
|
2
|
50
|
|
|
|
9
|
if ($yaml_content) { |
106
|
|
|
|
|
|
|
#my $yaml=YAML::Tiny->read_string($yaml_content) or die; |
107
|
2
|
|
|
|
|
282
|
my $yaml=decode_json($yaml_content); |
108
|
2
|
100
|
|
|
|
66
|
return $author unless $yaml->{'fork'}; |
109
|
1
|
|
|
|
|
11
|
my $source=$yaml->{source}{owner}{login}; |
110
|
1
|
50
|
|
|
|
3
|
die "No login in YAML for $link" unless $source; |
111
|
1
|
|
|
|
|
28
|
return $source; |
112
|
0
|
|
|
|
|
|
die; |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
|
die "No content"; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Alexandr Ciornii, C<< >> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 BUGS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
125
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
126
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SUPPORT |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
perldoc Github::Fork::Parent |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
You can also look for information at: |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * CPAN Ratings |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * Search CPAN |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Net::GitHub |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Copyright 2009-2017 Alexandr Ciornii. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
170
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
171
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; # End of Github::Fork::Parent |