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