line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plagger::Plugin::CustomFeed::GitHub; |
2
|
1
|
|
|
1
|
|
517
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
10
|
use base qw(Plagger::Plugin); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
310
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
584
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
32643
|
|
|
1
|
|
|
|
|
294
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
0
|
|
|
0
|
0
|
|
my ( $self, $context ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
$context->register_hook( $self, 'subscription.load' => $self->can('load'), ); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub load { |
17
|
0
|
|
|
0
|
0
|
|
my ( $self, $context, $args ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $feed = Plagger::Feed->new; |
20
|
0
|
|
|
0
|
|
|
$feed->aggregator( sub { $self->aggregate(@_) } ); |
|
0
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$context->subscription->add($feed); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub aggregate { |
27
|
0
|
|
|
0
|
0
|
|
my ( $self, $context, $args ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
my $token = $self->conf->{token} or return; |
30
|
0
|
0
|
|
|
|
|
my $users = $self->conf->{users} or return; |
31
|
0
|
0
|
|
|
|
|
$users = [$users] unless ref $users; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
34
|
0
|
|
|
|
|
|
my $header = HTTP::Headers->new( |
35
|
|
|
|
|
|
|
"Authorization" => "token $token", |
36
|
|
|
|
|
|
|
"Accept" => "application/atom+xml" |
37
|
|
|
|
|
|
|
); |
38
|
0
|
|
|
|
|
|
for my $user (@$users) { |
39
|
0
|
|
|
|
|
|
my $url = "https://github.com/$user"; |
40
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( 'GET', $url, $header ); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$context->log( debug => "Fetch feed from $url" ); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
unless ( $res->is_success ) { |
47
|
0
|
|
|
|
|
|
$context->log( error => "GitHub API failed: " . $res->status_line ); |
48
|
0
|
|
|
|
|
|
next; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $content = HTML::Entities::decode( $res->content ); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
Plagger::Plugin::Aggregator::Simple->handle_feed( $url, \$content ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |