Last active
December 22, 2015 16:58
-
-
Save ainame/6502426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Perl::Metrics::Simple; | |
use constant { | |
EXIT_STATUS_SUCCESS => 0, | |
PERL_MODULE_FILENAME_PATTERN => qr/\.(pm|pl)$/, | |
LIMIT_LINES_OF_CODE => 150, | |
}; | |
# .git/hooks/pre-commit.sample に書いてあるおなじみの処理 | |
system "git rev-parse --verify HEAD >/dev/null 2>&1"; | |
return exit 1 unless $? == EXIT_STATUS_SUCCESS; | |
sub get_modified_files { | |
my $output = `git diff-index --cached --name-only HEAD`; | |
chomp($output); | |
return split /\n/, $output; | |
} | |
sub convert_analysis_object { | |
my $file = shift; | |
my $analyzer = Perl::Metrics::Simple->new; | |
my $analysis = $analyzer->analyze_files($file); | |
return $analysis; | |
} | |
my @excess_limit_files = grep { | |
$file->lines > LIMIT_LINES_OF_CODE | |
} map { | |
convert_analysis_object($_) | |
} grep { | |
$_ =~ PERL_MODULE_FILENAME_PATTERN | |
} get_modified_files; | |
for my $file (@excess_limit_files) { | |
warn sprintf( | |
"%s: over limit(150) of lines of code(%s).\n", | |
$file->files->[0], $file->lines, | |
); | |
} | |
exit 1 unless scalar(@excess_limit_files) == 0; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LGTM