line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Group::Git::Github; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2013-05-04 20:18:31 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1276
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
10
|
1
|
|
|
1
|
|
2922
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
11
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
12
|
1
|
|
|
1
|
|
5
|
use version; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
13
|
1
|
|
|
1
|
|
74
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
14
|
1
|
|
|
1
|
|
6
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
15
|
1
|
|
|
1
|
|
948
|
use Net::GitHub; |
|
1
|
|
|
|
|
191674
|
|
|
1
|
|
|
|
|
43
|
|
16
|
1
|
|
|
1
|
|
11
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
520
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = version->new('0.7.7'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
extends 'Group::Git'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has github => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
#isa => 'Net::GitHub', |
25
|
|
|
|
|
|
|
builder => '_github', |
26
|
|
|
|
|
|
|
lazy => 1, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _repos { |
30
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
31
|
0
|
|
|
|
|
|
my ($conf) = $self->conf; |
32
|
0
|
|
|
|
|
|
my %repos = %{ $self->SUPER::_repos() }; |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $repo = $self->github->repos; |
35
|
0
|
|
|
|
|
|
my @list = $repo->list; |
36
|
0
|
|
|
|
|
|
my $page = 0; |
37
|
0
|
|
|
|
|
|
do { |
38
|
0
|
|
|
|
|
|
$page++; |
39
|
0
|
0
|
|
|
|
|
@list = $repo->query( $repo->next_url ) if !@list; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
for my $repo (@list) { |
42
|
0
|
|
|
|
|
|
my $url = $repo->{git_url}; |
43
|
|
|
|
|
|
|
# convert urls of the form: |
44
|
|
|
|
|
|
|
# git://github.com/ivanwills/meteor.git |
45
|
|
|
|
|
|
|
# to |
46
|
|
|
|
|
|
|
# git@github.com:ivanwills/meteor.git |
47
|
|
|
|
|
|
|
# as git doesn't like the form that github uses |
48
|
0
|
|
|
|
|
|
$url =~ s{git://github.com/([^/]+)}{git\@github.com:$1}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$repos{ $repo->{name} } = Group::Git::Repo->new( |
51
|
0
|
|
|
|
|
|
name => path($repo->{name}), |
52
|
|
|
|
|
|
|
git => $url, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# tag fork repos and original repos |
56
|
0
|
0
|
|
|
|
|
if ( $repo->{fork} ) { |
57
|
0
|
|
|
|
|
|
push @{ $conf->{tags}{forks} }, $repo->{name}; |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
|
push @{ $conf->{tags}{originals} }, $repo->{name}; |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
@list = (); |
64
|
|
|
|
|
|
|
} while ( $repo->has_next_page ); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return \%repos; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _github { |
70
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
71
|
0
|
|
|
|
|
|
my $conf = $self->conf; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return Net::GitHub->new( |
74
|
|
|
|
|
|
|
$conf->{access_token} |
75
|
|
|
|
|
|
|
? ( access_token => $conf->{access_token} ) |
76
|
|
|
|
|
|
|
: ( |
77
|
|
|
|
|
|
|
login => $conf->{username} ? $conf->{username} : prompt( -prompt => 'github.com username : ' ), |
78
|
|
|
|
|
|
|
pass => $conf->{password} ? $conf->{password} : prompt( -prompt => 'github.com password : ', -echo => '*' ), |
79
|
|
|
|
|
|
|
( |
80
|
|
|
|
|
|
|
$conf->{otp} |
81
|
0
|
0
|
|
|
|
|
? ( pass => prompt( -prompt => 'github.com password : ', -echo => '*' ) ) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
82
|
|
|
|
|
|
|
: () |
83
|
|
|
|
|
|
|
) |
84
|
|
|
|
|
|
|
) |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Group::Git::Github - Adds reading all repositories you have access to on github.com |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 VERSION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This documentation refers to Group::Git::Github version 0.7.7. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Group::Git::Github; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# pull (or clone missing) all repositories that joeblogs has created/forked |
106
|
|
|
|
|
|
|
my $ggg = Group::Git::Github->new( |
107
|
|
|
|
|
|
|
conf => { |
108
|
|
|
|
|
|
|
username => 'joeblogs@gmail.com', |
109
|
|
|
|
|
|
|
password => 'myverysecurepassword', |
110
|
|
|
|
|
|
|
}, |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# or if you have two factor auth turned on |
114
|
|
|
|
|
|
|
my $ggg = Group::Git::Github->new( |
115
|
|
|
|
|
|
|
conf => { |
116
|
|
|
|
|
|
|
username => 'joeblogs@gmail.com', |
117
|
|
|
|
|
|
|
password => 'myverysecurepassword', |
118
|
|
|
|
|
|
|
ota => 1, |
119
|
|
|
|
|
|
|
}, |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Alternitavely using personal access tokens |
123
|
|
|
|
|
|
|
# You can setup at https://github.com/settings/applications |
124
|
|
|
|
|
|
|
my $ggg = Group::Git::Github->new( |
125
|
|
|
|
|
|
|
conf => { |
126
|
|
|
|
|
|
|
access_token => '...', |
127
|
|
|
|
|
|
|
}, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# list all repositories |
131
|
|
|
|
|
|
|
my $repositories = $ggg->repo(); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# do something to each repository |
134
|
|
|
|
|
|
|
for my $repo (keys %{$repositories}) { |
135
|
|
|
|
|
|
|
# eg do a pull |
136
|
|
|
|
|
|
|
$ggg->pull($repo); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 DESCRIPTION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Reads all repositories for the configured user. Note: if no username, password |
142
|
|
|
|
|
|
|
or access_token is set you will be prompted to enter a username and password. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 Configuration |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
There are three configuration parameters that are currently used |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=over 4 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item access_token |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
A github OAuth personal access token. If supplied then username and password |
153
|
|
|
|
|
|
|
are ignored. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item username |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Specify the user to login as, if not specified the user will be prompted to |
158
|
|
|
|
|
|
|
enter a username. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item password |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Specify the password to login with, if not specified the user will be prompted |
163
|
|
|
|
|
|
|
to enter a password. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=back |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
There are no known bugs in this module. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Patches are welcome. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Copyright (c) 2013 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
192
|
|
|
|
|
|
|
All rights reserved. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
195
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
196
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
197
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
198
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |