File tree 4 files changed +80
-0
lines changed
lib/overcommit/hook/pre_commit
spec/overcommit/hook/pre_commit
4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## master
4
4
5
+ * Add [ ` Pronto ` ] ( https://github.com/mmozuras/pronto ) pre-commit hook
5
6
* Add [ ` hadolint ` ] ( https://github.com/lukasmartinelli/hadolint ) pre-commit hook
6
7
* Use the ` core.hooksPath ` Git configuration option when installing hooks
7
8
Original file line number Diff line number Diff line change @@ -430,6 +430,13 @@ PreCommit:
430
430
install_command : ' pip install pep8'
431
431
include : ' **/*.py'
432
432
433
+ Pronto :
434
+ enabled : false
435
+ description : ' Analyzing with pronto'
436
+ required_executable : ' pronto'
437
+ install_command : ' gem install pronto'
438
+ flags : ['run', '--staged --exit-code']
439
+
433
440
PuppetLint :
434
441
enabled : false
435
442
description : ' Analyze with puppet-lint'
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::PreCommit
2
+ # Runs `pronto`
3
+ #
4
+ # @see https://github.com/mmozuras/pronto
5
+ class Pronto < Base
6
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type |
7
+ type . include? ( 'E' ) ? :error : :warning
8
+ end
9
+
10
+ def run
11
+ result = execute ( command )
12
+ return :pass if result . success?
13
+
14
+ extract_messages (
15
+ result . stdout . split ( "\n " ) ,
16
+ /^(?<file>(?:\w :)?[^:]+):(?<line>\d +) (?<type>[^ ]+)/ ,
17
+ MESSAGE_TYPE_CATEGORIZER ,
18
+ )
19
+ end
20
+ end
21
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::PreCommit ::Pronto do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ subject { described_class . new ( config , context ) }
7
+
8
+ before do
9
+ subject . stub ( :applicable_files ) . and_return ( %w[ file1.rb file2.rb ] )
10
+ end
11
+
12
+ context 'when pronto exits successfully' do
13
+ before do
14
+ result = double ( 'result' )
15
+ result . stub ( :success? ) . and_return ( true )
16
+ subject . stub ( :execute ) . and_return ( result )
17
+ end
18
+
19
+ it { should pass }
20
+ end
21
+
22
+ context 'when pronto exits unsucessfully' do
23
+ let ( :result ) { double ( 'result' ) }
24
+
25
+ before do
26
+ result . stub ( :success? ) . and_return ( false )
27
+ subject . stub ( :execute ) . and_return ( result )
28
+ end
29
+
30
+ context 'and it reports an error' do
31
+ before do
32
+ result . stub ( :stdout ) . and_return ( [
33
+ 'file2.rb:10 E: IDENTICAL code found in :iter.' ,
34
+ ] . join ( "\n " ) )
35
+ end
36
+
37
+ it { should fail_hook }
38
+ end
39
+
40
+ context 'and it reports a warning' do
41
+ before do
42
+ result . stub ( :stdout ) . and_return ( [
43
+ 'file1.rb:12 W: Line is too long. [107/80]' ,
44
+ 'file2.rb:14 I: Prefer single-quoted strings'
45
+ ] . join ( "\n " ) )
46
+ end
47
+
48
+ it { should warn }
49
+ end
50
+ end
51
+ end
You can’t perform that action at this time.
0 commit comments