blib/lib/Dist/Zilla/Plugin/SlackNotify.pm

filter: Statementstmt 45.3% 34 / 75 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 72.7% 8 / 11 Podpod 100% 2 / 2 totaltotal 37.6% 44 / 117 CC 14 SCAR 39.6
CC
14
Cov
34%
after_release
110.0
_build_message
30.0
mvp_multivalue_args
2.0
CRAP 52.5
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Plugin::SlackNotify;
4 1 $Dist::Zilla::Plugin::SlackNotify::VERSION = '0.003';
5 # ABSTRACT: Publish a notification on Slack after release
6  
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 with 'Dist::Zilla::Role::AfterRelease';
9  
10 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Dist::Zilla::Plugin::EmailNotify;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 has webhook_url => (
17 is => 'ro',
18 isa => 'Str',
19 predicate => 'has_webhook_url',
20 );
21  
22 1 has channel => (
23 is => 'ro',
24 isa => 'ArrayRef[Str]',
25 predicate => 'has_channel',
26 );
27  
28 1 has username => (
29 is => 'ro',
30 isa => 'Str',
31 predicate => 'has_username',
32 );
33  
34 1 has icon_url => (
35 is => 'ro',
36 isa => 'Str',
37 predicate => 'has_icon_url',
38 clearer => 'clear_icon_url',
39 );
40  
41 1 has icon_emoji => (
42 is => 'ro',
43 isa => 'Str',
44 predicate => 'has_icon_emoji',
45 );
46  
47 1 has message => (
48 is => 'rw',
49 isa => 'Str',
50 lazy_build => 1,
51 );
52  
53 0 ▶sub mvp_multivalue_args { qw/channel/ }
Subroutine mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod documented
54  
55 0 ▶sub after_release {
Subroutine after_release: not called CC=10 SCAR=47.0
Pod documented
56 0 my $self = shift;
57  
58 0 ▶ unless ( $self->has_webhook_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_webhook_url) 0 0 0
59 0 $self->log( "No webhook_url configured, no notification sent" );
60 0 return 1;
61 }
62  
63 0 ▶ if ( $self->has_icon_url && $self->has_icon_emoji ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_icon_url and $self->has_icon_emoji) 0 0 0
Condition0%0/3
$self->has_icon_url and $self->has_icon_emoji
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_icon_url and $self->has_icon_emoji
$self->has_icon_url $self->has_icon_emoji
Truth table0%0/3
A and B
A= $self->has_icon_urlB= $self->has_icon_emoji
ABresult
0X0
100
111
64 0 $self->clear_icon_url;
65 0 $self->log( "Both icon_url and icon_emoji set, will use icon_url" );
66 }
67  
68 0 my $ua = LWP::UserAgent->new;
69 0 my $res;
70 0 ▶ for ( @{ $self->channel || [ undef ] } ) {
Condition0%0/2
$self->channel || [undef]
l!l
00
MC/DC0%0/1
$self->channel || [undef]
$self->channel
Truth table0%0/2
A
A= $self->channel
Aresult
11
00
71 0 my %payload;
72 0 ▶ $payload{channel} = $_ if $self->has_channel;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_channel 0 0 0
73 0 ▶ $payload{username} = $self->username if $self->has_username;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_username 0 0 0
74 0 ▶ $payload{icon_url} = $self->icon_url if $self->has_icon_url;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_icon_url 0 0 0
75 0 ▶ $payload{icon_emoji} = $self->icon_emoji if $self->has_icon_emoji;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_icon_emoji 0 0 0
76 0 $payload{text} = $self->message;
77  
78 0 $res = $ua->post( $self->webhook_url,
79 'Content-Type' => 'application/json',
80 Content => encode_json( \%payload ),
81 );
82 }
83  
84 0 return $res->is_success;
85 }
86  
87 0 ▶sub _build_message {
Subroutine _build_message: not called CC=5 SCAR=34.0
88 0 my $self = shift;
89  
90 0 my @message;
91  
92 0 my $name = $self->zilla->name;
93 0 my $version = $self->zilla->version;
94 0 ▶ my $user = $ENV{USER} ? "`$ENV{USER}`" : 'An unknown user';
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'USER'} ? : 0 0 0
95  
96 0 push @message, sprintf( "%s has released version %s of %s", $user, $version, $name );
97 0 push @message, '';
98  
99 0 push @message, 'Changes:';
100 0 push @message, map { "> $_" } $self->Dist::Zilla::Plugin::EmailNotify::extract_last_release( 'Changes' );
101 0 push @message, '';
102  
103 0 ▶ my $res = $self->zilla->distmeta || die "Internal error";
Condition0%0/2
$self->zilla->distmeta || die('Internal error')
l!l
00
MC/DC0%0/1
$self->zilla->distmeta || die('Internal error')
$self->zilla->distmeta
Truth table0%0/2
A
A= $self->zilla->distmeta
Aresult
11
00
104 0 ▶ push @message, sprintf( "Homepage: %s", $res->{homepage} ) if $res->{homepage};
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"homepage"} 0 0 0
105  
106 0 my $repo = $res->{repository};
107 0 ▶ push @message, sprintf( "Repository: %s", $repo->{web} ) if $repo->{web};
Branch: 1 branch
BranchTrueFalseTotal
if $repo->{"web"} 0 0 0
108  
109 0 push @message, '';
110 0 push @message, "Authors:";
111 0 push @message, map { " - $_" } @{ $self->zilla->authors };
112  
113 0 return join( "\n", @message );
114 }
115  
116 1 __PACKAGE__->meta->make_immutable;
117 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119 1 1;
120  
121 __END__
↑ Summary