overcommit 0.51.0 → 0.52.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be2c25e83a10d44e88ecee58e5b2638e31e13562b0b272aa68e47656b095c582
4
- data.tar.gz: 2b568ff85f265e88387b05b88e41146f2a341b3d22f571c461910c1833a76359
3
+ metadata.gz: 9d272167cf4a2702f9a368d4c4cb0ade3236256c13166d2e18e4bfc9a1f52dd4
4
+ data.tar.gz: 2241202866ac631d15ee8925364db27794342badd181d18a7effd8a0cbe5a60f
5
5
  SHA512:
6
- metadata.gz: 4ae077600ff211f4bbc13a6dd97e1fe8ab4a625fb8918751f1238ee7b9d832f686cdaa42e9e2f1be5f2da0a150fd008532e45a3c45b48f23a3bb118a1d190597
7
- data.tar.gz: 4db41972b13aa4c47c230fca0828f4a1d8d7491a09e8e753f0db27bd9f8cf1906b618ad0612e7dbfc84aa3e532529e4d2b41092f85e7bad91b303cd7f7e01017
6
+ metadata.gz: bc3efeeb6257f78b5fb490613808375ce52281b4f250bce2275a90a7105f9ce88191de56ab985b00944abffa04650b1cb700d3ecc7bbba0ddae9da139561b7dc
7
+ data.tar.gz: ee4d8d6006e42c77b936adc2efe62d93742ce461dd2f117165feadfd82dcebde152b1531a984ea91370ec0005a6b108f1e1f5b683641a5d5d2fe90f4ae63a498
@@ -337,6 +337,23 @@ PreCommit:
337
337
  flags: ['-IEHnw']
338
338
  keywords: ['FContext','FDescribe','FIt','FMeasure','FSpecify','FWhen']
339
339
 
340
+ GoFmt:
341
+ enabled: true
342
+ description: 'Fix with go fmt'
343
+ required_executable: 'go'
344
+ command: ['go', 'fmt']
345
+ parallelize: false
346
+ include: '**/*.go'
347
+
348
+ GolangciLint:
349
+ enabled: false
350
+ description: 'Analyze with golangci-lint'
351
+ required_executable: 'golangci-lint'
352
+ install_command: 'go get github.com/golangci/golangci-lint/cmd/golangci-lint'
353
+ flags: ['--out-format=line-number', '--print-issued-lines=false']
354
+ command: ['golangci-lint', 'run']
355
+ include: '**/*.go'
356
+
340
357
  GoLint:
341
358
  enabled: false
342
359
  description: 'Analyze with golint'
@@ -1253,6 +1270,20 @@ PrePush:
1253
1270
  required_executable: 'git-lfs'
1254
1271
  install_command: 'brew install git-lfs'
1255
1272
 
1273
+ GolangciLint:
1274
+ enabled: false
1275
+ description: 'Analyze with golangci-lint'
1276
+ required_executable: 'golangci-lint'
1277
+ install_command: 'go get github.com/golangci/golangci-lint/cmd/golangci-lint'
1278
+ flags: ['--out-format=line-number', '--print-issued-lines=false']
1279
+ command: ['golangci-lint', 'run']
1280
+
1281
+ GoTest:
1282
+ enabled: false
1283
+ description: 'Run go test suite'
1284
+ required_executable: 'go'
1285
+ command: ['go', 'test', './...']
1286
+
1256
1287
  Minitest:
1257
1288
  enabled: false
1258
1289
  description: 'Run Minitest test suite'
@@ -79,12 +79,17 @@ module Overcommit::Hook
79
79
  @config['enabled'] != false
80
80
  end
81
81
 
82
+ def excluded?
83
+ exclude_branches.any? { |p| File.fnmatch(p, current_branch) }
84
+ end
85
+
82
86
  def skip?
83
87
  @config['skip']
84
88
  end
85
89
 
86
90
  def run?
87
91
  enabled? &&
92
+ !excluded? &&
88
93
  !(@config['requires_files'] && applicable_files.empty?)
89
94
  end
90
95
 
@@ -276,5 +281,13 @@ module Overcommit::Hook
276
281
  status
277
282
  end
278
283
  end
284
+
285
+ def exclude_branches
286
+ @config['exclude_branches'] || []
287
+ end
288
+
289
+ def current_branch
290
+ @current_branch ||= Overcommit::GitRepo.current_branch
291
+ end
279
292
  end
280
293
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs go fmt for all modified Go files
5
+ class GoFmt < Base
6
+ def run
7
+ errors = []
8
+ applicable_files.each do |file|
9
+ result = execute(command, args: [file])
10
+ errors << (result.stdout + result.stderr) unless result.success?
11
+ end
12
+ return :pass if errors.empty?
13
+
14
+ [:fail, errors.join("\n")]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `golangci-lint run` against any modified packages
5
+ #
6
+ # @see https://github.com/golangci/golangci-lint
7
+ class GolangciLint < Base
8
+ def run
9
+ packages = applicable_files.map { |f| File.dirname(f) }.uniq
10
+ result = execute(command, args: packages)
11
+ return :pass if result.success?
12
+ return [:fail, result.stderr] unless result.stderr.empty?
13
+
14
+ extract_messages(
15
+ result.stdout.split("\n"),
16
+ /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
17
+ nil
18
+ )
19
+ end
20
+ end
21
+ end
@@ -19,9 +19,9 @@ module Overcommit::Hook::PreCommit
19
19
  json_messages.map do |message|
20
20
  Overcommit::Hook::Message.new(
21
21
  :error,
22
- message[:filename],
23
- message[:line],
24
- message[:description]
22
+ message['filename'],
23
+ message['line'],
24
+ "#{message['filename']}:#{message['line']} #{message['rule']} #{message['description']}"
25
25
  )
26
26
  end
27
27
  end
@@ -8,5 +8,21 @@ module Overcommit::Hook::PrePush
8
8
  extend Forwardable
9
9
 
10
10
  def_delegators :@context, :remote_name, :remote_url, :pushed_refs
11
+
12
+ def run?
13
+ super &&
14
+ !exclude_remotes.include?(remote_name) &&
15
+ (include_remote_ref_deletions? || !@context.remote_ref_deletion?)
16
+ end
17
+
18
+ private
19
+
20
+ def exclude_remotes
21
+ @config['exclude_remotes'] || []
22
+ end
23
+
24
+ def include_remote_ref_deletions?
25
+ @config['include_remote_ref_deletions']
26
+ end
11
27
  end
12
28
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PrePush
4
+ # Runs `go test ./...` command on prepush
5
+ class GoTest < Base
6
+ def run
7
+ result = execute(command)
8
+ return :pass if result.success?
9
+
10
+ output = result.stdout + result.stderr
11
+ [:fail, output]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PrePush
4
+ # Runs golangci-lint
5
+ #
6
+ # @see https://github.com/golangci/golangci-lint
7
+ class GolangciLint < Base
8
+ def run
9
+ result = execute(command)
10
+ return :pass if result.success?
11
+
12
+ output = result.stdout + result.stderr
13
+ [:fail, output]
14
+ end
15
+ end
16
+ end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Overcommit::Hook::PrePush
4
- # Prevents destructive updates to specified branches.
4
+ # Prevents updates to specified branches.
5
+ # Accepts a 'destructive_only' option globally or per branch
6
+ # to only prevent destructive updates.
5
7
  class ProtectedBranches < Base
6
8
  def run
7
9
  return :pass unless illegal_pushes.any?
@@ -17,32 +19,55 @@ module Overcommit::Hook::PrePush
17
19
 
18
20
  def illegal_pushes
19
21
  @illegal_pushes ||= pushed_refs.select do |pushed_ref|
20
- protected?(pushed_ref.remote_ref) && allow_non_destructive?(pushed_ref)
22
+ protected?(pushed_ref)
21
23
  end
22
24
  end
23
25
 
24
- def protected?(remote_ref)
26
+ def protected?(ref)
27
+ find_pattern(ref.remote_ref)&.destructive?(ref)
28
+ end
29
+
30
+ def find_pattern(remote_ref)
25
31
  ref_name = remote_ref[%r{refs/heads/(.*)}, 1]
26
- return false if ref_name.nil?
27
- protected_branch_patterns.any? do |pattern|
28
- File.fnmatch(pattern, ref_name)
32
+ return if ref_name.nil?
33
+
34
+ patterns.find do |pattern|
35
+ File.fnmatch(pattern.to_s, ref_name)
29
36
  end
30
37
  end
31
38
 
32
- def protected_branch_patterns
33
- @protected_branch_patterns ||= Array(config['branches']).
34
- concat(Array(config['branch_patterns']))
39
+ def patterns
40
+ @patterns ||= fetch_patterns
35
41
  end
36
42
 
37
- def destructive_only?
43
+ def fetch_patterns
44
+ branch_configurations.map do |pattern|
45
+ if pattern.is_a?(Hash)
46
+ Pattern.new(pattern.keys.first, pattern['destructive_only'])
47
+ else
48
+ Pattern.new(pattern, global_destructive_only?)
49
+ end
50
+ end
51
+ end
52
+
53
+ def branch_configurations
54
+ config['branches'].to_a + config['branch_patterns'].to_a
55
+ end
56
+
57
+ def global_destructive_only?
38
58
  config['destructive_only'].nil? || config['destructive_only']
39
59
  end
40
60
 
41
- def allow_non_destructive?(ref)
42
- if destructive_only?
43
- ref.destructive?
44
- else
45
- true
61
+ Pattern = Struct.new('Pattern', :name, :destructive_only) do
62
+ alias_method :to_s, :name
63
+ alias_method :destructive_only?, :destructive_only
64
+
65
+ def destructive?(ref)
66
+ if destructive_only?
67
+ ref.destructive?
68
+ else
69
+ true
70
+ end
46
71
  end
47
72
  end
48
73
  end
@@ -13,6 +13,15 @@ module Overcommit::HookContext
13
13
  @args[1]
14
14
  end
15
15
 
16
+ def remote_ref_deletion?
17
+ return @remote_ref_deletion if defined?(@remote_ref_deletion)
18
+
19
+ @remote_ref_deletion ||= input_lines.
20
+ first.
21
+ split(' ').
22
+ first == '(deleted)'
23
+ end
24
+
16
25
  def pushed_refs
17
26
  input_lines.map do |line|
18
27
  PushedRef.new(*line.split(' '))
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.51.0'
5
+ VERSION = '0.52.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overcommit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.0
4
+ version: 0.52.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-02 00:00:00.000000000 Z
11
+ date: 2019-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: childprocess
@@ -139,8 +139,10 @@ files:
139
139
  - lib/overcommit/hook/pre_commit/foodcritic.rb
140
140
  - lib/overcommit/hook/pre_commit/forbidden_branches.rb
141
141
  - lib/overcommit/hook/pre_commit/ginkgo_focus.rb
142
+ - lib/overcommit/hook/pre_commit/go_fmt.rb
142
143
  - lib/overcommit/hook/pre_commit/go_lint.rb
143
144
  - lib/overcommit/hook/pre_commit/go_vet.rb
145
+ - lib/overcommit/hook/pre_commit/golangci_lint.rb
144
146
  - lib/overcommit/hook/pre_commit/hadolint.rb
145
147
  - lib/overcommit/hook/pre_commit/haml_lint.rb
146
148
  - lib/overcommit/hook/pre_commit/hard_tabs.rb
@@ -210,6 +212,8 @@ files:
210
212
  - lib/overcommit/hook/pre_push/base.rb
211
213
  - lib/overcommit/hook/pre_push/brakeman.rb
212
214
  - lib/overcommit/hook/pre_push/cargo_test.rb
215
+ - lib/overcommit/hook/pre_push/go_test.rb
216
+ - lib/overcommit/hook/pre_push/golangci_lint.rb
213
217
  - lib/overcommit/hook/pre_push/minitest.rb
214
218
  - lib/overcommit/hook/pre_push/php_unit.rb
215
219
  - lib/overcommit/hook/pre_push/protected_branches.rb