Skip to content

Commit 16eded3

Browse files
authoredMar 8, 2020
Add pronto to pre_push hooks (sds#706)
1 parent dc50788 commit 16eded3

File tree

8 files changed

+104
-14
lines changed

8 files changed

+104
-14
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ coverage/
33
pkg/
44
.bundle
55
.idea
6+
.history/
7+
.vscode/

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ aborted.
582582
* [Brakeman](lib/overcommit/hook/pre_push/brakeman.rb)
583583
* [Minitest](lib/overcommit/hook/pre_push/minitest.rb)
584584
* [PhpUnit](lib/overcommit/hook/pre_push/php_unit.rb)
585+
* [Pronto](lib/overcommit/hook/pre_push/pronto.rb)
585586
* [ProtectedBranches](lib/overcommit/hook/pre_push/protected_branches.rb)
586587
* [Pytest](lib/overcommit/hook/pre_push/pytest.rb)
587588
* [PythonNose](lib/overcommit/hook/pre_push/python_nose.rb)

‎config/default.yml

+7
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,13 @@ PrePush:
12971297
flags: ['--bootstrap', 'vendor/autoload.php', 'tests']
12981298
install_command: 'composer require --dev phpunit/phpunit'
12991299

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+
13001307
ProtectedBranches:
13011308
enabled: false
13021309
description: 'Check for illegal pushes to protected branches'
+3-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
# frozen_string_literal: true
22

3+
require 'overcommit/hook/shared/pronto'
4+
35
module Overcommit::Hook::PreCommit
46
# Runs `pronto`
57
#
68
# @see https://github.com/mmozuras/pronto
79
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
2211
end
2312
end

‎lib/overcommit/hook/pre_push/base.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'forwardable'
4+
require 'overcommit/utils/messages_utils'
45

56
module Overcommit::Hook::PrePush
67
# Functionality common to all pre-push hooks.
@@ -17,6 +18,10 @@ def run?
1718

1819
private
1920

21+
def extract_messages(*args)
22+
Overcommit::Utils::MessagesUtils.extract_messages(*args)
23+
end
24+
2025
def exclude_remotes
2126
@config['exclude_remotes'] || []
2227
end
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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

‎lib/overcommit/hook/shared/pronto.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

0 commit comments

Comments
 (0)
Please sign in to comment.