line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Text::Travis; |
2
|
1
|
|
|
1
|
|
425
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has media_id => sub { |
5
|
|
|
|
|
|
|
shift->url->path =~ m!^/(.*/builds/\d+)$! ? $1 : ''; |
6
|
|
|
|
|
|
|
}; |
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
1
|
|
sub provider_name {'Travis'} |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub learn { |
11
|
0
|
|
|
0
|
1
|
|
my ($self, $c, $cb) = @_; |
12
|
0
|
|
|
|
|
|
my $ua = $self->ua; |
13
|
0
|
|
|
|
|
|
my $url = Mojo::URL->new('https://api.travis-ci.org/repositories'); |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
push @{$url->path}, split '/', $self->media_id; |
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Mojo::IOLoop->delay( |
18
|
|
|
|
|
|
|
sub { |
19
|
0
|
|
|
0
|
|
|
my $delay = shift; |
20
|
0
|
|
|
|
|
|
$ua->get($url, $delay->begin); |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
sub { |
23
|
0
|
|
|
0
|
|
|
my ($ua, $tx) = @_; |
24
|
0
|
|
|
|
|
|
$self->{json} = $tx->res->json; |
25
|
0
|
|
|
|
|
|
$self->$cb; |
26
|
|
|
|
|
|
|
}, |
27
|
0
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub to_embed { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my $json = $self->{json}; |
33
|
0
|
|
0
|
|
|
|
my $description = $json->{message} || ''; |
34
|
0
|
|
|
|
|
|
my $title; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if ($json->{finished_at}) { |
|
|
0
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
$title = sprintf 'Build %s at %s', $json->{status} ? 'failed' : 'succeeded', $json->{finished_at}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($json->{started_at}) { |
40
|
0
|
|
|
|
|
|
$title = sprintf 'Started building at %s.', $json->{started_at}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
|
|
|
|
|
$title = 'Build has not been started.'; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($description) { |
47
|
0
|
0
|
|
|
|
|
$description = "$json->{author_name}: $description" if $json->{author_name}; |
48
|
|
|
|
|
|
|
return $self->tag( |
49
|
|
|
|
|
|
|
div => class => 'link-embedder text-html', |
50
|
|
|
|
|
|
|
sub { |
51
|
|
|
|
|
|
|
join( |
52
|
|
|
|
|
|
|
'', |
53
|
|
|
|
|
|
|
$self->tag( |
54
|
|
|
|
|
|
|
div => class => 'link-embedder-media', |
55
|
|
|
|
|
|
|
sub { |
56
|
0
|
|
|
|
|
|
$self->tag(img => src => 'https://travis-ci.com/img/travis-mascot-200px.png', alt => 'Travis logo'); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
), |
59
|
|
|
|
|
|
|
$self->tag(h3 => $title), |
60
|
|
|
|
|
|
|
$self->tag(p => $description), |
61
|
|
|
|
|
|
|
$self->tag( |
62
|
|
|
|
|
|
|
div => class => 'link-embedder-link', |
63
|
|
|
|
|
|
|
sub { |
64
|
0
|
|
|
|
|
|
$self->tag(a => href => $self->url, title => $self->url, $self->url); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
) |
67
|
0
|
|
|
0
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $self->SUPER::to_embed(@_); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=encoding utf8 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Mojolicious::Plugin::LinkEmbedder::Link::Text::Travis - https://travis-ci.org link |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 media_id |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$str = $self->media_id; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Example C<$str>: "Nordaaker/convos/builds/47421379". |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 provider_name |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 METHODS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 learn |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 to_embed |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns data about the HTML page in a div tag. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Jan Henning Thorsen |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |