File tree 8 files changed +104
-14
lines changed
spec/overcommit/hook/pre_push
8 files changed +104
-14
lines changed Original file line number Diff line number Diff line change @@ -3,3 +3,5 @@ coverage/
3
3
pkg /
4
4
.bundle
5
5
.idea
6
+ .history /
7
+ .vscode /
Original file line number Diff line number Diff line change @@ -582,6 +582,7 @@ aborted.
582
582
* [Brakeman](lib/overcommit/hook/pre_push/brakeman.rb)
583
583
* [Minitest](lib/overcommit/hook/pre_push/minitest.rb)
584
584
* [PhpUnit](lib/overcommit/hook/pre_push/php_unit.rb)
585
+ * [Pronto](lib/overcommit/hook/pre_push/pronto.rb)
585
586
* [ProtectedBranches](lib/overcommit/hook/pre_push/protected_branches.rb)
586
587
* [Pytest](lib/overcommit/hook/pre_push/pytest.rb)
587
588
* [PythonNose](lib/overcommit/hook/pre_push/python_nose.rb)
Original file line number Diff line number Diff line change @@ -1297,6 +1297,13 @@ PrePush:
1297
1297
flags : ['--bootstrap', 'vendor/autoload.php', 'tests']
1298
1298
install_command : ' composer require --dev phpunit/phpunit'
1299
1299
1300
+ Pronto :
1301
+ enabled : false
1302
+ description : ' Analyzing with pronto'
1303
+ required_executable : ' pronto'
1304
+ install_command : ' gem install pronto'
1305
+ flags : ['run', '--exit-code']
1306
+
1300
1307
ProtectedBranches :
1301
1308
enabled : false
1302
1309
description : ' Check for illegal pushes to protected branches'
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ require 'overcommit/hook/shared/pronto'
4
+
3
5
module Overcommit ::Hook ::PreCommit
4
6
# Runs `pronto`
5
7
#
6
8
# @see https://github.com/mmozuras/pronto
7
9
class Pronto < Base
8
- MESSAGE_TYPE_CATEGORIZER = lambda do |type |
9
- type . include? ( 'E' ) ? :error : :warning
10
- end
11
-
12
- def run
13
- result = execute ( command )
14
- return :pass if result . success?
15
-
16
- extract_messages (
17
- result . stdout . split ( "\n " ) ,
18
- /^(?<file>(?:\w :)?[^:]+):(?<line>\d +) (?<type>[^ ]+)/ ,
19
- MESSAGE_TYPE_CATEGORIZER ,
20
- )
21
- end
10
+ include Overcommit ::Hook ::Shared ::Pronto
22
11
end
23
12
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require 'forwardable'
4
+ require 'overcommit/utils/messages_utils'
4
5
5
6
module Overcommit ::Hook ::PrePush
6
7
# Functionality common to all pre-push hooks.
@@ -17,6 +18,10 @@ def run?
17
18
18
19
private
19
20
21
+ def extract_messages ( *args )
22
+ Overcommit ::Utils ::MessagesUtils . extract_messages ( *args )
23
+ end
24
+
20
25
def exclude_remotes
21
26
@config [ 'exclude_remotes' ] || [ ]
22
27
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'overcommit/hook/shared/pronto'
4
+
5
+ module Overcommit ::Hook ::PrePush
6
+ # Runs `pronto`
7
+ #
8
+ # @see https://github.com/mmozuras/pronto
9
+ class Pronto < Base
10
+ include Overcommit ::Hook ::Shared ::Pronto
11
+ end
12
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit ::Hook ::Shared
4
+ # Shared code used by all Pronto hooks. Runs pronto linter.
5
+ module Pronto
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
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Overcommit ::Hook ::PrePush ::Pronto do
6
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
7
+ let ( :context ) { double ( 'context' ) }
8
+ subject { described_class . new ( config , context ) }
9
+
10
+ before do
11
+ subject . stub ( :applicable_files ) . and_return ( %w[ file1.rb file2.rb ] )
12
+ end
13
+
14
+ context 'when pronto exits successfully' do
15
+ before do
16
+ result = double ( 'result' )
17
+ result . stub ( :success? ) . and_return ( true )
18
+ subject . stub ( :execute ) . and_return ( result )
19
+ end
20
+
21
+ it { should pass }
22
+ end
23
+
24
+ context 'when pronto exits unsucessfully' do
25
+ let ( :result ) { double ( 'result' ) }
26
+
27
+ before do
28
+ result . stub ( :success? ) . and_return ( false )
29
+ subject . stub ( :execute ) . and_return ( result )
30
+ end
31
+
32
+ context 'and it reports an error' do
33
+ before do
34
+ result . stub ( :stdout ) . and_return ( [
35
+ 'file2.rb:10 E: IDENTICAL code found in :iter.' ,
36
+ ] . join ( "\n " ) )
37
+ end
38
+
39
+ it { should fail_hook }
40
+ end
41
+
42
+ context 'and it reports a warning' do
43
+ before do
44
+ result . stub ( :stdout ) . and_return ( [
45
+ 'file1.rb:12 W: Line is too long. [107/80]' ,
46
+ 'file2.rb:14 I: Prefer single-quoted strings'
47
+ ] . join ( "\n " ) )
48
+ end
49
+
50
+ it { should warn }
51
+ end
52
+ end
53
+ end
You can’t perform that action at this time.
0 commit comments