| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::GitHooks::Plugin::RubyCompile; |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
2683444
|
use strict; |
|
|
8
|
|
|
|
|
27
|
|
|
|
8
|
|
|
|
|
339
|
|
|
4
|
8
|
|
|
8
|
|
46
|
use warnings; |
|
|
8
|
|
|
|
|
17
|
|
|
|
8
|
|
|
|
|
272
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
124
|
use base 'App::GitHooks::Plugin'; |
|
|
8
|
|
|
|
|
81
|
|
|
|
8
|
|
|
|
|
5527
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# External dependencies. |
|
9
|
8
|
|
|
8
|
|
6391
|
use System::Command; |
|
|
8
|
|
|
|
|
119454
|
|
|
|
8
|
|
|
|
|
76
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Internal dependencies. |
|
12
|
8
|
|
|
8
|
|
5328
|
use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); |
|
|
8
|
|
|
|
|
1912
|
|
|
|
8
|
|
|
|
|
7712
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
App::GitHooks::Plugin::RubyCompile - Verify that staged Ruby files compile. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Verify that staged Ruby files compile by running ruby -c against them. |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Warnings are suppressed with -W0. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 VERSION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Version 1.0.0 |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 get_file_pattern() |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Return a pattern to filter the files this plugin should analyze. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $file_pattern = App::GitHooks::Plugin::RubyCompile->get_file_pattern( |
|
43
|
|
|
|
|
|
|
app => $app, |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_file_pattern |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
6
|
|
|
6
|
1
|
1325311
|
return qr/\.(?:rb)$/x; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 get_file_check_description() |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Return a description of the check performed on files by the plugin and that |
|
57
|
|
|
|
|
|
|
will be displayed to the user, if applicable, along with an indication of the |
|
58
|
|
|
|
|
|
|
success or failure of the plugin. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $description = App::GitHooks::Plugin::RubyCompile->get_file_check_description(); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get_file_check_description |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
5
|
|
|
5
|
1
|
7584
|
return 'The file passes ruby -c'; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 run_pre_commit_file() |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Code to execute for each file as part of the pre-commit hook. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $success = App::GitHooks::Plugin::RubyCompile->run_pre_commit_file(); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub run_pre_commit_file |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
2
|
|
|
2
|
1
|
8460
|
my ( $class, %args ) = @_; |
|
81
|
2
|
|
|
|
|
50
|
my $file = delete( $args{'file'} ); |
|
82
|
2
|
|
|
|
|
36
|
my $git_action = delete( $args{'git_action'} ); |
|
83
|
2
|
|
|
|
|
20
|
my $app = delete( $args{'app'} ); |
|
84
|
2
|
|
|
|
|
128
|
my $staged_changes = $app->get_staged_changes(); |
|
85
|
2
|
|
|
|
|
83
|
my $repository = $app->get_repository(); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Ignore deleted files. |
|
88
|
2
|
50
|
|
|
|
58
|
return $PLUGIN_RETURN_SKIPPED |
|
89
|
|
|
|
|
|
|
if $git_action eq 'D'; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Execute ruby -c. |
|
92
|
2
|
|
|
|
|
154
|
my $path = $repository->work_tree() . '/' . $file; |
|
93
|
2
|
|
|
|
|
16082
|
my ( $pid, $stdin, $stdout, $stderr ) = System::Command->spawn( 'ruby', '-W0', '-c', $path ); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Retrieve the output. |
|
96
|
0
|
|
|
|
|
|
chomp( my $message_out = do { local $/ = undef; <$stdout> } ); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Raise an exception if we didn't get "syntax OK". |
|
99
|
0
|
0
|
|
|
|
|
if ( $message_out !~ /^Syntax\ OK$/x ) { |
|
100
|
0
|
|
|
|
|
|
my @warnings = <$stderr>; |
|
101
|
0
|
|
|
|
|
|
foreach my $warning ( @warnings ) { |
|
102
|
0
|
|
|
|
|
|
chomp( $warning ); |
|
103
|
0
|
|
|
|
|
|
$warning =~ s/^\Q$path\E:/Line /; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
0
|
|
|
|
|
|
die join( "\n", @warnings ) . "\n"; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $PLUGIN_RETURN_PASSED; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 BUGS |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
|
114
|
|
|
|
|
|
|
L. |
|
115
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
116
|
|
|
|
|
|
|
your bug as I make changes. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Big thanks to Guillaume Aubert! |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SUPPORT |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
perldoc App::GitHooks::Plugin::RubyCompile |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
You can also look for information at: |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=over |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * GitHub's request tracker |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * MetaCPAN |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L, |
|
155
|
|
|
|
|
|
|
C<< >>. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Copyright 2013-2014 Jacob Maurer. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under |
|
163
|
|
|
|
|
|
|
the terms of the GNU General Public License version 3 as published by the Free |
|
164
|
|
|
|
|
|
|
Software Foundation. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
|
167
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
|
168
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with |
|
171
|
|
|
|
|
|
|
this program. If not, see http://www.gnu.org/licenses/ |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |