File Coverage

blib/lib/App/CISetup/AppVeyor/ConfigFile.pm
Criterion Covered Total %
statement 40 40 100.0
branch 5 10 50.0
condition 1 3 33.3
subroutine 11 11 100.0
pod n/a
total 57 64 89.0


line stmt bran cond sub pod time code
1             package App::CISetup::AppVeyor::ConfigFile;
2              
3 1     1   328078 use strict;
  1         3  
  1         44  
4 1     1   7 use warnings;
  1         1  
  1         34  
5 1     1   8 use namespace::autoclean;
  1         2  
  1         14  
6 1     1   700 use autodie qw( :all );
  1         14677  
  1         8  
7              
8             our $VERSION = '0.17';
9              
10 1     1   22469 use App::CISetup::Types qw( Str );
  1         5  
  1         9  
11              
12 1     1   4913 use Moose;
  1         2  
  1         8  
13              
14             has email_address => (
15             is => 'ro',
16             isa => Str, # todo, better type
17             predicate => 'has_email_address',
18             );
19              
20             has slack_channel => (
21             is => 'ro',
22             isa => Str,
23             predicate => 'has_slack_channel',
24             );
25              
26             has encrypted_slack_key => (
27             is => 'ro',
28             isa => Str,
29             predicate => 'has_encrypted_slack_key',
30             );
31              
32             with 'App::CISetup::Role::ConfigFile';
33              
34             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
35             sub _create_config {
36 1     1   2 my $self = shift;
37              
38 1         14 return $self->_update_config(
39             {
40             skip_tags => 'true',
41             cache => ['C:\strawberry'],
42             install => [
43             'if not exist "C:\strawberry" cinst strawberryperl -y',
44             'set PATH=C:\strawberry\perl\bin;C:\strawberry\perl\site\bin;C:\strawberry\c\bin;%PATH%',
45             'cd %APPVEYOR_BUILD_FOLDER%',
46             'cpanm --installdeps . -n',
47             ],
48             build_script => ['perl -e 1'],
49             test_script => ['prove -lrvm t/'],
50             }
51             );
52             }
53              
54             sub _update_config {
55 4     4   11 my $self = shift;
56 4         11 my $appveyor = shift;
57              
58 4         32 $self->_update_notifications($appveyor);
59              
60 4         19 return $appveyor;
61             }
62             ## use critic
63              
64             sub _update_notifications {
65 4     4   11 my $self = shift;
66 4         8 my $appveyor = shift;
67              
68 4         12 my @notifications;
69 4 50 33     243 push @notifications, {
70             provider => 'Slack',
71             auth_token => {
72             secure => $self->encrypted_slack_key,
73             },
74             channel => $self->slack_channel,
75             on_build_failure => 'true',
76             on_build_status_changed => 'true',
77             on_build_success => 'true',
78             } if $self->has_encrypted_slack_key && $self->has_slack_channel;
79              
80 4 50       150 push @notifications, {
81             provider => 'Email',
82             subject => 'AppVeyor build {{status}}',
83             to => [ $self->email_address ],
84             on_build_failure => 'true',
85             on_build_status_changed => 'true',
86             on_build_success => 'false',
87             } if $self->has_email_address;
88              
89             $appveyor->{notifications} = \@notifications
90 4 50       39 if @notifications;
91              
92 4         17 return;
93             }
94              
95             my @BlocksOrder = qw(
96             version
97             skip_tags
98             init
99             environment
100             matrix
101             cache
102             services
103             install
104             before_build
105             build_script
106             after_build
107             before_test
108             test_script
109             after_test
110             artifacts
111             on_success
112             on_failure
113             on_finish
114             notifications
115             );
116              
117             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
118             sub _fix_up_yaml {
119 8     8   24 my $self = shift;
120 8         14 my $yaml = shift;
121              
122 8         38 $yaml = $self->_reorder_yaml_blocks( $yaml, \@BlocksOrder );
123              
124 8         39 return $yaml;
125             }
126              
127             sub _cisetup_flags {
128 4     4   13 my $self = shift;
129              
130 4         8 my %flags;
131 4 50       205 $flags{email_address} = $self->email_address
132             if $self->has_email_address;
133              
134 4 50       155 $flags{slack_channel} = $self->slack_channel
135             if $self->has_slack_channel;
136              
137 4         31 return \%flags;
138             }
139             ## use critic
140              
141             __PACKAGE__->meta->make_immutable;
142              
143             1;