line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TeamCity::Message; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15017
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
418
|
use Time::HiRes qw( time ); |
|
1
|
|
|
|
|
948
|
|
|
1
|
|
|
|
|
3
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
111
|
use Exporter qw( import ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
352
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
## no critic (Modules::ProhibitAutomaticExportation) |
13
|
|
|
|
|
|
|
our @EXPORT = qw( tc_message ); |
14
|
|
|
|
|
|
|
## use critic |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub tc_message { |
17
|
6
|
|
|
6
|
1
|
12658
|
my %args = @_; |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
50
|
|
|
19
|
my $type = delete $args{type} || 'message'; |
20
|
|
|
|
|
|
|
my $content = delete $args{content} |
21
|
6
|
50
|
|
|
|
11
|
or die 'You must provide a content argument to tc_message()'; |
22
|
|
|
|
|
|
|
|
23
|
6
|
|
|
|
|
10
|
my $msg = "##teamcity[$type"; |
24
|
|
|
|
|
|
|
|
25
|
6
|
100
|
|
|
|
10
|
if ( ref $content ) { |
26
|
4
|
|
|
|
|
4
|
for my $name ( sort keys %{$content} ) { |
|
4
|
|
|
|
|
13
|
|
27
|
5
|
|
|
|
|
6
|
my $value = $content->{$name}; |
28
|
5
|
|
|
|
|
9
|
$msg .= qq{ $name='} . _escape($value) . q{'}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$msg .= _timestamp() |
32
|
4
|
50
|
|
|
|
13
|
unless $content->{timestamp}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
2
|
50
|
|
|
|
4
|
$msg .= q{ '} . _escape($content) . q{'} or die $!; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
6
|
|
|
|
|
7
|
$msg .= "]\n"; |
39
|
|
|
|
|
|
|
|
40
|
6
|
|
|
|
|
7
|
return $msg; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _timestamp { |
44
|
4
|
|
|
4
|
|
8
|
my $now = time; |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
31
|
my ( $s, $mi, $h, $d, $mo, $y ) = ( gmtime($now) )[ 0 .. 5 ]; |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
10
|
my $float = ( $now - int($now) ); |
49
|
4
|
|
|
|
|
26
|
return sprintf( |
50
|
|
|
|
|
|
|
q{ timestamp='%4d-%02d-%02dT%02d:%02d:%02d.%03d'}, |
51
|
|
|
|
|
|
|
$y + 1900, $mo + 1, $d, |
52
|
|
|
|
|
|
|
$h, $mi, $s, |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# We only need 3 places of precision so if we multiply it be 1,000 we |
55
|
|
|
|
|
|
|
# can just treat it as an integer. |
56
|
|
|
|
|
|
|
$float * 1000, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _escape { |
61
|
7
|
|
|
7
|
|
8
|
my $str = shift; |
62
|
|
|
|
|
|
|
|
63
|
7
|
|
|
|
|
27
|
( my $esc = $str ) =~ s{(['|\]])}{|$1}g; |
64
|
7
|
|
|
|
|
12
|
$esc =~ s{\n}{|n}g; |
65
|
7
|
|
|
|
|
8
|
$esc =~ s{\r}{|r}g; |
66
|
|
|
|
|
|
|
|
67
|
7
|
|
|
|
|
20
|
return $esc; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# ABSTRACT: Generate TeamCity build messages |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |