overcommit 0.41.0 → 0.42.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +130 -4
  3. data/lib/overcommit/cli.rb +5 -0
  4. data/lib/overcommit/configuration_loader.rb +5 -1
  5. data/lib/overcommit/configuration_validator.rb +2 -1
  6. data/lib/overcommit/git_config.rb +1 -1
  7. data/lib/overcommit/hook/post_checkout/composer_install.rb +11 -0
  8. data/lib/overcommit/hook/post_checkout/yarn_install.rb +11 -0
  9. data/lib/overcommit/hook/post_commit/composer_install.rb +11 -0
  10. data/lib/overcommit/hook/post_commit/yarn_install.rb +11 -0
  11. data/lib/overcommit/hook/post_merge/composer_install.rb +11 -0
  12. data/lib/overcommit/hook/post_merge/yarn_install.rb +11 -0
  13. data/lib/overcommit/hook/post_rewrite/composer_install.rb +11 -0
  14. data/lib/overcommit/hook/post_rewrite/yarn_install.rb +11 -0
  15. data/lib/overcommit/hook/pre_commit/bundle_audit.rb +2 -1
  16. data/lib/overcommit/hook/pre_commit/chamber_compare.rb +41 -0
  17. data/lib/overcommit/hook/pre_commit/chamber_verification.rb +34 -0
  18. data/lib/overcommit/hook/pre_commit/go_lint.rb +9 -2
  19. data/lib/overcommit/hook/pre_commit/license_finder.rb +1 -1
  20. data/lib/overcommit/hook/pre_commit/line_endings.rb +2 -1
  21. data/lib/overcommit/hook/pre_commit/mdl.rb +1 -1
  22. data/lib/overcommit/hook/pre_commit/php_stan.rb +28 -0
  23. data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +27 -0
  24. data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +1 -1
  25. data/lib/overcommit/hook/pre_commit/rst_lint.rb +25 -0
  26. data/lib/overcommit/hook/shared/composer_install.rb +13 -0
  27. data/lib/overcommit/hook/shared/yarn_install.rb +13 -0
  28. data/lib/overcommit/hook_context/pre_push.rb +6 -0
  29. data/lib/overcommit/hook_runner.rb +1 -1
  30. data/lib/overcommit/hook_signer.rb +17 -10
  31. data/lib/overcommit/printer.rb +0 -2
  32. data/lib/overcommit/subprocess.rb +1 -1
  33. data/lib/overcommit/version.rb +1 -1
  34. data/template-dir/hooks/commit-msg +1 -1
  35. data/template-dir/hooks/overcommit-hook +1 -1
  36. data/template-dir/hooks/post-checkout +1 -1
  37. data/template-dir/hooks/post-commit +1 -1
  38. data/template-dir/hooks/post-merge +1 -1
  39. data/template-dir/hooks/post-rewrite +1 -1
  40. data/template-dir/hooks/pre-commit +1 -1
  41. data/template-dir/hooks/pre-push +1 -1
  42. data/template-dir/hooks/pre-rebase +1 -1
  43. metadata +19 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27b302156918dca6c24185cf0cbb4c88ee1ff17a
4
- data.tar.gz: c537a8ca33fbeaa4aeb0aa73cb47fa6a23beac80
3
+ metadata.gz: e46e06664c4b84241863650f3b1c0d0316f9c66b
4
+ data.tar.gz: 16c1e91603f5c6e3aef1316cd4a1aaeb60998eef
5
5
  SHA512:
6
- metadata.gz: a1c4c0011bb62eea08e898950211af0fa16053067dca6e91c50f06193b889492c5f71c035015e321af3ad35b6b742f49324b205ce4db7de5f337a64cc1fca968
7
- data.tar.gz: d550e63d8fc852da8503657c99041304d850dc45936044e16294f7ed72d05d793493059eaf0e357e51cfdf608ea43ecf4a2d435c322bc3e9efa1d1e2bbb1f4e9
6
+ metadata.gz: 7629c771c3a572032c7036af72799a0b3127fca7386d804c3fdb8609c766134853385564faa7c49296b86add33f7fe2de3ee339cdd814868c7f7cdc4142cd4f2
7
+ data.tar.gz: db1da032a04d2673e2b10875ea9e0e3fa9b0b6a7afe4af780ad5eb32f6e94b3f0531636d642ffb451cb01a850a7405178a7de248b8bbb7dea7307a5f91ad5753
@@ -184,15 +184,42 @@ PreCommit:
184
184
  description: 'Check for case-insensitivity conflicts'
185
185
  quiet: true
186
186
 
187
+ ChamberCompare:
188
+ enabled: false
189
+ description: 'Check that settings are equivalent between namespaces'
190
+ required_executable: 'chamber'
191
+ flags: ['compare']
192
+ install_command: 'gem install chamber'
193
+ namespaces:
194
+ - ['development']
195
+ - ['test']
196
+ - ['production']
197
+ exclusions: []
198
+ include: &chamber_settings_files
199
+ - 'config/settings*.yml'
200
+ - 'config/settings*.yml.erb'
201
+ - 'config/settings/**/*.yml'
202
+ - 'config/settings/**/*.yml.erb'
203
+ - 'settings*.yml'
204
+ - 'settings*.yml.erb'
205
+ - 'settings/**/*.yml'
206
+ - 'settings/**/*.yml.erb'
207
+
187
208
  ChamberSecurity:
188
209
  enabled: false
189
210
  description: 'Check that settings have been secured with Chamber'
190
211
  required_executable: 'chamber'
191
212
  flags: ['secure', '--files']
192
213
  install_command: 'gem install chamber'
193
- include:
194
- - 'config/settings.yml'
195
- - 'config/settings/**/*.yml'
214
+ include: *chamber_settings_files
215
+
216
+ ChamberVerification:
217
+ enabled: false
218
+ description: 'Verify that all settings changes have been approved'
219
+ required_executable: 'chamber'
220
+ flags: ['sign', '--verify']
221
+ install_command: 'gem install chamber'
222
+ include: *chamber_settings_files
196
223
 
197
224
  CoffeeLint:
198
225
  enabled: false
@@ -415,7 +442,7 @@ PreCommit:
415
442
 
416
443
  Mdl:
417
444
  enabled: false
418
- description: 'Analyze with mdl'
445
+ description: 'Analyze markdown files with mdl'
419
446
  required_executable: 'mdl'
420
447
  install_command: 'gem install mdl'
421
448
  include: '**/*.md'
@@ -427,6 +454,14 @@ PreCommit:
427
454
  required_executable: 'grep'
428
455
  flags: ['-IHn', "^<<<<<<<[ \t]"]
429
456
 
457
+ PuppetMetadataJsonLint:
458
+ enabled: false
459
+ description: 'Checking module metadata'
460
+ flags: ['--strict-license', '--strict-dependencies', '--fail-on-warning']
461
+ include: 'metadata.json'
462
+ required_executable: 'metadata-json-lint'
463
+ install_command: 'gem install metadata-json-lint'
464
+
430
465
  NginxTest:
431
466
  enabled: false
432
467
  description: 'Test nginx configs'
@@ -463,6 +498,14 @@ PreCommit:
463
498
  flags: ['--standard=PSR2', '--report=csv']
464
499
  include: '**/*.php'
465
500
 
501
+ PhpStan:
502
+ description: 'Analyze with phpstan'
503
+ enabled: false
504
+ command: 'phpstan'
505
+ flags: ['analyze', '--errorFormat=raw']
506
+ include:
507
+ - '**/*.php'
508
+
466
509
  Pronto:
467
510
  enabled: false
468
511
  description: 'Analyzing with pronto'
@@ -558,6 +601,13 @@ PreCommit:
558
601
  - '**/Gemfile'
559
602
  - '**/Rakefile'
560
603
 
604
+ RstLint:
605
+ enabled: false
606
+ description: 'Analyze reStructuredText files with rst-lint'
607
+ required_executable: 'rst-lint'
608
+ install_command: 'pip install restructuredtext_lint'
609
+ include: '**/*.rst'
610
+
561
611
  RuboCop:
562
612
  enabled: false
563
613
  description: 'Analyze with RuboCop'
@@ -763,6 +813,15 @@ PostCheckout:
763
813
  - 'Gemfile.lock'
764
814
  - '*.gemspec'
765
815
 
816
+ ComposerInstall:
817
+ enabled: false
818
+ description: 'Install composer dependencies'
819
+ requires_files: true
820
+ required_executable: 'composer'
821
+ install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer'
822
+ flags: ['install']
823
+ include: 'composer.json'
824
+
766
825
  IndexTags:
767
826
  enabled: false
768
827
  description: 'Generate tags file from source'
@@ -785,6 +844,16 @@ PostCheckout:
785
844
  quiet: true
786
845
  recursive: false
787
846
 
847
+ YarnInstall:
848
+ enabled: false
849
+ description: 'Install Yarn dependencies'
850
+ requires_files: true
851
+ required_executable: 'yarn'
852
+ flags: ['install']
853
+ include:
854
+ - 'package.json'
855
+ - 'yarn.lock'
856
+
788
857
  # Hooks that run after a commit is created.
789
858
  PostCommit:
790
859
  ALL:
@@ -820,6 +889,15 @@ PostCommit:
820
889
  install_command: 'npm install --save-dev commitplease'
821
890
  flags: ['-1']
822
891
 
892
+ ComposerInstall:
893
+ enabled: false
894
+ description: 'Install composer dependencies'
895
+ requires_files: true
896
+ required_executable: 'composer'
897
+ install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer'
898
+ flags: ['install']
899
+ include: 'composer.json'
900
+
823
901
  GitGuilt:
824
902
  enabled: false
825
903
  description: 'Calculate changes in blame since last commit'
@@ -850,6 +928,16 @@ PostCommit:
850
928
  quiet: true
851
929
  recursive: false
852
930
 
931
+ YarnInstall:
932
+ enabled: false
933
+ description: 'Install Yarn dependencies'
934
+ requires_files: true
935
+ required_executable: 'yarn'
936
+ flags: ['install']
937
+ include:
938
+ - 'package.json'
939
+ - 'yarn.lock'
940
+
853
941
  # Hooks that run after `git merge` executes successfully (no merge conflicts).
854
942
  PostMerge:
855
943
  ALL:
@@ -877,6 +965,15 @@ PostMerge:
877
965
  - 'Gemfile.lock'
878
966
  - '*.gemspec'
879
967
 
968
+ ComposerInstall:
969
+ enabled: false
970
+ description: 'Install composer dependencies'
971
+ requires_files: true
972
+ required_executable: 'composer'
973
+ install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer'
974
+ flags: ['install']
975
+ include: 'composer.json'
976
+
880
977
  IndexTags:
881
978
  enabled: false
882
979
  description: 'Generate tags file from source'
@@ -899,6 +996,16 @@ PostMerge:
899
996
  quiet: true
900
997
  recursive: false
901
998
 
999
+ YarnInstall:
1000
+ enabled: false
1001
+ description: 'Install Yarn dependencies'
1002
+ requires_files: true
1003
+ required_executable: 'yarn'
1004
+ flags: ['install']
1005
+ include:
1006
+ - 'package.json'
1007
+ - 'yarn.lock'
1008
+
902
1009
  # Hooks that run after a commit is modified by an amend or rebase.
903
1010
  PostRewrite:
904
1011
  ALL:
@@ -926,6 +1033,15 @@ PostRewrite:
926
1033
  - 'Gemfile.lock'
927
1034
  - '*.gemspec'
928
1035
 
1036
+ ComposerInstall:
1037
+ enabled: false
1038
+ description: 'Install composer dependencies'
1039
+ requires_files: true
1040
+ required_executable: 'composer'
1041
+ install_command: 'curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer'
1042
+ flags: ['install']
1043
+ include: 'composer.json'
1044
+
929
1045
  IndexTags:
930
1046
  enabled: false
931
1047
  description: 'Generate tags file from source'
@@ -948,6 +1064,16 @@ PostRewrite:
948
1064
  quiet: true
949
1065
  recursive: false
950
1066
 
1067
+ YarnInstall:
1068
+ enabled: false
1069
+ description: 'Install Yarn dependencies'
1070
+ requires_files: true
1071
+ required_executable: 'yarn'
1072
+ flags: ['install']
1073
+ include:
1074
+ - 'package.json'
1075
+ - 'yarn.lock'
1076
+
951
1077
  # Hooks that run during `git push`, after remote refs have been updated but
952
1078
  # before any objects have been transferred.
953
1079
  PrePush:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'overcommit'
2
4
  require 'optparse'
3
5
 
@@ -27,6 +29,9 @@ module Overcommit
27
29
  when :run_all
28
30
  run_all
29
31
  end
32
+ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => ex
33
+ puts ex
34
+ exit 78 # EX_CONFIG
30
35
  rescue Overcommit::Exceptions::HookContextLoadError => ex
31
36
  puts ex
32
37
  exit 64 # EX_USAGE
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
 
3
5
  module Overcommit
@@ -68,7 +70,9 @@ module Overcommit
68
70
  end
69
71
 
70
72
  config
71
- rescue => error
73
+ rescue Overcommit::Exceptions::ConfigurationSignatureChanged
74
+ raise
75
+ rescue StandardError => error
72
76
  raise Overcommit::Exceptions::ConfigurationError,
73
77
  "Unable to load configuration from '#{file}': #{error}",
74
78
  error.backtrace
@@ -95,7 +95,7 @@ module Overcommit
95
95
  errors = []
96
96
 
97
97
  Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
98
- hash.fetch(hook_type, {}).each do |hook_name, _|
98
+ hash.fetch(hook_type, {}).each_key do |hook_name|
99
99
  next if hook_name == 'ALL'
100
100
 
101
101
  unless hook_name =~ /\A[A-Za-z0-9]+\z/
@@ -175,3 +175,4 @@ module Overcommit
175
175
  end
176
176
  end
177
177
  end
178
+ # rubocop:enable Metrics/ClassLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/LineLength
@@ -13,7 +13,7 @@ module Overcommit
13
13
 
14
14
  def hooks_path
15
15
  path = `git config --get core.hooksPath`.chomp
16
- return File.join(Overcommit::Utils.repo_root, '.git', 'hooks') if path.empty?
16
+ return File.join(Overcommit::Utils.git_dir, 'hooks') if path.empty?
17
17
  File.absolute_path(path)
18
18
  end
19
19
  end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/composer_install'
2
+
3
+ module Overcommit::Hook::PostCheckout
4
+ # Runs `composer install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::ComposerInstall}
8
+ class ComposerInstall < Base
9
+ include Overcommit::Hook::Shared::ComposerInstall
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/yarn_install'
2
+
3
+ module Overcommit::Hook::PostCheckout
4
+ # Runs `yarn install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::YarnInstall}
8
+ class YarnInstall < Base
9
+ include Overcommit::Hook::Shared::YarnInstall
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/composer_install'
2
+
3
+ module Overcommit::Hook::PostCommit
4
+ # Runs `composer install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::ComposerInstall}
8
+ class ComposerInstall < Base
9
+ include Overcommit::Hook::Shared::ComposerInstall
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/yarn_install'
2
+
3
+ module Overcommit::Hook::PostCommit
4
+ # Runs `yarn install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::YarnInstall}
8
+ class YarnInstall < Base
9
+ include Overcommit::Hook::Shared::YarnInstall
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/composer_install'
2
+
3
+ module Overcommit::Hook::PostMerge
4
+ # Runs `composer install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::ComposerInstall}
8
+ class ComposerInstall < Base
9
+ include Overcommit::Hook::Shared::ComposerInstall
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/yarn_install'
2
+
3
+ module Overcommit::Hook::PostMerge
4
+ # Runs `yarn install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::YarnInstall}
8
+ class YarnInstall < Base
9
+ include Overcommit::Hook::Shared::YarnInstall
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/composer_install'
2
+
3
+ module Overcommit::Hook::PostRewrite
4
+ # Runs `composer install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::ComposerInstall}
8
+ class ComposerInstall < Base
9
+ include Overcommit::Hook::Shared::ComposerInstall
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'overcommit/hook/shared/yarn_install'
2
+
3
+ module Overcommit::Hook::PostRewrite
4
+ # Runs `yarn install` when a change is detected in the repository's
5
+ # dependencies.
6
+ #
7
+ # @see {Overcommit::Hook::Shared::YarnInstall}
8
+ class YarnInstall < Base
9
+ include Overcommit::Hook::Shared::YarnInstall
10
+ end
11
+ end
@@ -7,7 +7,8 @@ module Overcommit::Hook::PreCommit
7
7
 
8
8
  def run
9
9
  # Ignore if Gemfile.lock is not tracked by git
10
- ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
10
+ ignored_files = execute(%W[git ls-files -o -i --exclude-standard -- #{LOCK_FILE}]).
11
+ stdout.split("\n")
11
12
  return :pass if ignored_files.include?(LOCK_FILE)
12
13
 
13
14
  result = execute(command)
@@ -0,0 +1,41 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `chamber compare` against a configurable set of namespaces.
3
+ #
4
+ # @see https://github.com/thekompanee/chamber/wiki/Git-Commit-Hooks#chamber-compare-pre-commit-hook
5
+ # rubocop:disable Metrics/MethodLength
6
+ class ChamberCompare < Base
7
+ def run
8
+ config['namespaces'].each_index do |index|
9
+ first = config['namespaces'][index]
10
+ second = config['namespaces'][index + 1]
11
+
12
+ next unless second
13
+
14
+ result = execute(
15
+ command,
16
+ args: [
17
+ "--first=#{first.join(' ')}",
18
+ "--second=#{second.join(' ')}",
19
+ ],
20
+ )
21
+
22
+ unless result.stdout.empty?
23
+ trimmed_result = result.stdout.split("\n")
24
+ 5.times { trimmed_result.shift }
25
+ trimmed_result = trimmed_result.join("\n")
26
+
27
+ return [
28
+ :warn,
29
+ "It appears your namespace settings between #{first} and " \
30
+ "#{second} are not in sync:\n\n#{trimmed_result}\n\n" \
31
+ "Run: chamber compare --first=#{first.join(' ')} " \
32
+ "--second=#{second.join(' ')}",
33
+ ]
34
+ end
35
+ end
36
+
37
+ :pass
38
+ end
39
+ end
40
+ # rubocop:enable Metrics/MethodLength
41
+ end
@@ -0,0 +1,34 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `chamber sign --verify`.
3
+ #
4
+ # @see https://github.com/thekompanee/chamber/wiki/Git-Commit-Hooks#chamber-verification-pre-commit-hook
5
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
6
+ class ChamberVerification < Base
7
+ def run
8
+ approver_name = config.fetch('approver_name', 'your approver')
9
+ approver_email = config['approver_email'] ? " (#{config['approver_email']})" : nil
10
+
11
+ result = execute(command)
12
+
13
+ return :pass if result.stdout.empty? && result.stderr.empty?
14
+ return :pass if result.stderr =~ /no signature key was found/
15
+
16
+ output = [
17
+ result.stdout.empty? ? nil : result.stdout,
18
+ result.stderr.empty? ? nil : result.stderr,
19
+ ].
20
+ compact.
21
+ join("\n\n")
22
+
23
+ output = "\n\n#{output}" unless output.empty?
24
+
25
+ [
26
+ :warn,
27
+ "One or more of your settings files does not match the signature.\n" \
28
+ "Talk to #{approver_name}#{approver_email} about getting them " \
29
+ "approved.#{output}",
30
+ ]
31
+ end
32
+ end
33
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
34
+ end
@@ -4,8 +4,15 @@ module Overcommit::Hook::PreCommit
4
4
  # @see https://github.com/golang/lint
5
5
  class GoLint < Base
6
6
  def run
7
- result = execute(command, args: applicable_files)
8
- output = result.stdout + result.stderr
7
+ output = ''
8
+
9
+ # golint doesn't accept multiple file arguments if
10
+ # they belong to different packages
11
+ applicable_files.each do |gofile|
12
+ result = execute(command, args: Array(gofile))
13
+ output += result.stdout + result.stderr
14
+ end
15
+
9
16
  # Unfortunately the exit code is always 0
10
17
  return :pass if output.empty?
11
18
 
@@ -1,6 +1,6 @@
1
1
  module Overcommit::Hook::PreCommit
2
2
  # Runs LicenseFinder if any of your package manager declaration files have changed
3
- # See more about LicenseFinder at https://github.com/pivotal/LicenseFinde
3
+ # See more about LicenseFinder at https://github.com/pivotal/LicenseFinder
4
4
  class LicenseFinder < Base
5
5
  def run
6
6
  result = execute(command)
@@ -53,7 +53,8 @@ module Overcommit::Hook::PreCommit
53
53
  raise 'Unable to access git tree' unless result.success?
54
54
 
55
55
  result.stdout.split("\0").map do |file_info|
56
- i, _w, _attr, path = file_info.split
56
+ info, path = file_info.split("\t")
57
+ i = info.split.first
57
58
  next if i == 'l/-text' # ignore binary files
58
59
  next if i == "l/#{eol}"
59
60
  path
@@ -3,7 +3,7 @@ module Overcommit::Hook::PreCommit
3
3
  #
4
4
  # @see https://github.com/mivok/markdownlint
5
5
  class Mdl < Base
6
- MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
6
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):\s(?<msg>.+)/
7
7
 
8
8
  def run
9
9
  result = execute(command, args: applicable_files)
@@ -0,0 +1,28 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `phpstan` against any modified PHP files.
3
+ # For running `phpstan` with Laravel, it requires setup with `ide_helper`.
4
+ #
5
+ # References:
6
+ # https://github.com/phpstan/phpstan/issues/239
7
+ # https://gist.github.com/edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2
8
+ class PhpStan < Base
9
+ MESSAGE_REGEX = /^(?<file>.+)\:(?<line>\d+)\:(?<message>.+)/
10
+
11
+ def run
12
+ messages = []
13
+
14
+ result = execute(command, args: applicable_files)
15
+
16
+ unless result.success?
17
+ messages += result.stdout.lstrip.split("\n")
18
+ end
19
+
20
+ return :pass if messages.empty?
21
+
22
+ extract_messages(
23
+ messages,
24
+ MESSAGE_REGEX
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ module Overcommit::Hook::PreCommit
2
+ #
3
+ # Run's the Puppet metadata linter. It has support for adding options
4
+ # in the .overcommit.yaml
5
+ #
6
+ # @see https://voxpupuli.org/blog/2014/11/06/linting-metadata-json/
7
+ #
8
+ class PuppetMetadataJsonLint < Base
9
+ MESSAGE_REGEX = /\((?<type>.*)\).*/
10
+
11
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
12
+ type == 'WARN' ? :warning : :error
13
+ end
14
+
15
+ def run
16
+ result = execute(command, args: applicable_files)
17
+ output = result.stdout.chomp.gsub(/^"|"$/, '')
18
+ return :pass if result.success? && output.empty?
19
+
20
+ extract_messages(
21
+ output.split("\n"),
22
+ MESSAGE_REGEX,
23
+ MESSAGE_TYPE_CATEGORIZER
24
+ )
25
+ end
26
+ end
27
+ end
@@ -8,7 +8,7 @@ module Overcommit
8
8
  ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)/
9
9
 
10
10
  def run
11
- result = execute(command)
11
+ result = execute(command, args: applicable_files)
12
12
 
13
13
  return :pass if result.success?
14
14
  return [:fail, result.stderr] unless result.stderr.empty?
@@ -0,0 +1,25 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `rst-lint` against any modified reStructuredText files
3
+ #
4
+ # @see https://github.com/twolfson/restructuredtext-lint
5
+ class RstLint < Base
6
+ MESSAGE_REGEX = /
7
+ ^(?<type>INFO|WARNING|ERROR|SEVERE)(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s(?<msg>.+)
8
+ /x
9
+
10
+ def run
11
+ result = execute(command, args: applicable_files)
12
+ output = result.stdout.chomp
13
+
14
+ return :pass if result.success?
15
+ return [:fail, result.stderr] unless result.stderr.empty?
16
+
17
+ # example message:
18
+ # WARNING README.rst:7 Title underline too short.
19
+ extract_messages(
20
+ output.split("\n"),
21
+ MESSAGE_REGEX
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Overcommit::Hook::Shared
2
+ # Shared code used by all ComposerInstall hooks. Runs `composer install` when
3
+ # a change is detected in the repository's dependencies.
4
+ #
5
+ # @see https://getcomposer.org/
6
+ module ComposerInstall
7
+ def run
8
+ result = execute(command)
9
+ return :fail, result.stdout unless result.success?
10
+ :pass
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Overcommit::Hook::Shared
2
+ # Shared code used by all YarnInstall hooks. Runs `yarn install` when a change
3
+ # is detected in the repository's dependencies.
4
+ #
5
+ # @see https://yarnpkg.com/
6
+ module YarnInstall
7
+ def run
8
+ result = execute(command)
9
+ return :fail, result.stderr unless result.success?
10
+ :pass
11
+ end
12
+ end
13
+ end
@@ -17,6 +17,12 @@ module Overcommit::HookContext
17
17
  end
18
18
  end
19
19
 
20
+ def modified_files
21
+ @modified_files ||= Overcommit::GitRepo.modified_files(
22
+ refs: "#{pushed_refs[0].remote_sha1}..#{pushed_refs[0].local_sha1}"
23
+ )
24
+ end
25
+
20
26
  PushedRef = Struct.new(:local_ref, :local_sha1, :remote_ref, :remote_sha1) do
21
27
  def forced?
22
28
  !(created? || deleted? || overwritten_commits.empty?)
@@ -156,7 +156,7 @@ module Overcommit
156
156
  rescue Overcommit::Exceptions::MessageProcessingError => ex
157
157
  status = :fail
158
158
  output = ex.message
159
- rescue => ex
159
+ rescue StandardError => ex
160
160
  status = :fail
161
161
  output = "Hook raised unexpected error\n#{ex.message}\n#{ex.backtrace.join("\n")}"
162
162
  end
@@ -32,25 +32,27 @@ module Overcommit
32
32
  # Otherwise this is an ad hoc hook using an existing hook script
33
33
  hook_config = @config.for_hook(@hook_name, @context.hook_class_name)
34
34
 
35
- command = Array(hook_config['command'] ||
36
- hook_config['required_executable'])
35
+ command = Array(hook_config['command'] || hook_config['required_executable'])
37
36
 
38
- unless !@config.verify_signatures? || signable_file?(command.first)
37
+ if @config.verify_signatures? &&
38
+ signable_file?(command.first) &&
39
+ !Overcommit::GitRepo.tracked?(command.first)
39
40
  raise Overcommit::Exceptions::InvalidHookDefinition,
40
- 'Hook must specify a `required_executable` or `command` that ' \
41
- 'is tracked by git (i.e. is a path relative to the root ' \
42
- 'of the repository) so that it can be signed'
41
+ 'Hook specified a `required_executable` or `command` that ' \
42
+ 'is a path relative to the root of the repository, and so ' \
43
+ 'must be tracked by Git in order to be signed'
43
44
  end
44
45
 
45
- File.join(Overcommit::Utils.repo_root, command.first)
46
+ File.join(Overcommit::Utils.repo_root, command.first.to_s)
46
47
  end
47
48
  end
48
49
  end
49
50
 
50
51
  def signable_file?(file)
52
+ return unless file
51
53
  sep = Overcommit::OS.windows? ? '\\' : File::SEPARATOR
52
- file.start_with?(".#{sep}") &&
53
- Overcommit::GitRepo.tracked?(file)
54
+ file.start_with?(".#{sep}") ||
55
+ file.start_with?(Overcommit::Utils.repo_root)
54
56
  end
55
57
 
56
58
  # Return whether the signature for this hook has changed since it was last
@@ -85,7 +87,12 @@ module Overcommit
85
87
  dup.
86
88
  tap { |config| IGNORED_CONFIG_KEYS.each { |k| config.delete(k) } }
87
89
 
88
- Digest::SHA256.hexdigest(hook_contents + hook_config.to_s)
90
+ content_to_sign =
91
+ if signable_file?(hook_path) && Overcommit::GitRepo.tracked?(hook_path)
92
+ hook_contents
93
+ end
94
+
95
+ Digest::SHA256.hexdigest(content_to_sign.to_s + hook_config.to_s)
89
96
  end
90
97
 
91
98
  def hook_contents
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'monitor'
4
2
 
5
3
  module Overcommit
@@ -36,7 +36,7 @@ module Overcommit
36
36
  if options[:input]
37
37
  begin
38
38
  process.io.stdin.puts(options[:input])
39
- rescue # rubocop:disable Lint/HandleExceptions
39
+ rescue StandardError # rubocop:disable Lint/HandleExceptions
40
40
  # Silently ignore if the standard input stream of the spawned
41
41
  # process is closed before we get a chance to write to it. This
42
42
  # happens on JRuby a lot.
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.41.0'.freeze
5
+ VERSION = '0.42.0'.freeze
6
6
  end
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
@@ -107,7 +107,7 @@ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
107
107
  exit 1
108
108
  rescue Overcommit::Exceptions::InvalidHookSignature
109
109
  exit 1
110
- rescue => error
110
+ rescue StandardError => error
111
111
  puts error.message
112
112
  puts error.backtrace
113
113
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overcommit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.0
4
+ version: 0.42.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brigade Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-25 00:00:00.000000000 Z
12
+ date: 2018-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -83,29 +83,37 @@ files:
83
83
  - lib/overcommit/hook/post_checkout/base.rb
84
84
  - lib/overcommit/hook/post_checkout/bower_install.rb
85
85
  - lib/overcommit/hook/post_checkout/bundle_install.rb
86
+ - lib/overcommit/hook/post_checkout/composer_install.rb
86
87
  - lib/overcommit/hook/post_checkout/index_tags.rb
87
88
  - lib/overcommit/hook/post_checkout/npm_install.rb
88
89
  - lib/overcommit/hook/post_checkout/submodule_status.rb
90
+ - lib/overcommit/hook/post_checkout/yarn_install.rb
89
91
  - lib/overcommit/hook/post_commit/base.rb
90
92
  - lib/overcommit/hook/post_commit/bower_install.rb
91
93
  - lib/overcommit/hook/post_commit/bundle_install.rb
92
94
  - lib/overcommit/hook/post_commit/commitplease.rb
95
+ - lib/overcommit/hook/post_commit/composer_install.rb
93
96
  - lib/overcommit/hook/post_commit/git_guilt.rb
94
97
  - lib/overcommit/hook/post_commit/index_tags.rb
95
98
  - lib/overcommit/hook/post_commit/npm_install.rb
96
99
  - lib/overcommit/hook/post_commit/submodule_status.rb
100
+ - lib/overcommit/hook/post_commit/yarn_install.rb
97
101
  - lib/overcommit/hook/post_merge/base.rb
98
102
  - lib/overcommit/hook/post_merge/bower_install.rb
99
103
  - lib/overcommit/hook/post_merge/bundle_install.rb
104
+ - lib/overcommit/hook/post_merge/composer_install.rb
100
105
  - lib/overcommit/hook/post_merge/index_tags.rb
101
106
  - lib/overcommit/hook/post_merge/npm_install.rb
102
107
  - lib/overcommit/hook/post_merge/submodule_status.rb
108
+ - lib/overcommit/hook/post_merge/yarn_install.rb
103
109
  - lib/overcommit/hook/post_rewrite/base.rb
104
110
  - lib/overcommit/hook/post_rewrite/bower_install.rb
105
111
  - lib/overcommit/hook/post_rewrite/bundle_install.rb
112
+ - lib/overcommit/hook/post_rewrite/composer_install.rb
106
113
  - lib/overcommit/hook/post_rewrite/index_tags.rb
107
114
  - lib/overcommit/hook/post_rewrite/npm_install.rb
108
115
  - lib/overcommit/hook/post_rewrite/submodule_status.rb
116
+ - lib/overcommit/hook/post_rewrite/yarn_install.rb
109
117
  - lib/overcommit/hook/pre_commit/author_email.rb
110
118
  - lib/overcommit/hook/pre_commit/author_name.rb
111
119
  - lib/overcommit/hook/pre_commit/base.rb
@@ -115,7 +123,9 @@ files:
115
123
  - lib/overcommit/hook/pre_commit/bundle_check.rb
116
124
  - lib/overcommit/hook/pre_commit/bundle_outdated.rb
117
125
  - lib/overcommit/hook/pre_commit/case_conflicts.rb
126
+ - lib/overcommit/hook/pre_commit/chamber_compare.rb
118
127
  - lib/overcommit/hook/pre_commit/chamber_security.rb
128
+ - lib/overcommit/hook/pre_commit/chamber_verification.rb
119
129
  - lib/overcommit/hook/pre_commit/coffee_lint.rb
120
130
  - lib/overcommit/hook/pre_commit/credo.rb
121
131
  - lib/overcommit/hook/pre_commit/css_lint.rb
@@ -152,8 +162,10 @@ files:
152
162
  - lib/overcommit/hook/pre_commit/pep8.rb
153
163
  - lib/overcommit/hook/pre_commit/php_cs.rb
154
164
  - lib/overcommit/hook/pre_commit/php_lint.rb
165
+ - lib/overcommit/hook/pre_commit/php_stan.rb
155
166
  - lib/overcommit/hook/pre_commit/pronto.rb
156
167
  - lib/overcommit/hook/pre_commit/puppet_lint.rb
168
+ - lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb
157
169
  - lib/overcommit/hook/pre_commit/pycodestyle.rb
158
170
  - lib/overcommit/hook/pre_commit/pydocstyle.rb
159
171
  - lib/overcommit/hook/pre_commit/pyflakes.rb
@@ -163,6 +175,7 @@ files:
163
175
  - lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb
164
176
  - lib/overcommit/hook/pre_commit/rake_target.rb
165
177
  - lib/overcommit/hook/pre_commit/reek.rb
178
+ - lib/overcommit/hook/pre_commit/rst_lint.rb
166
179
  - lib/overcommit/hook/pre_commit/rubo_cop.rb
167
180
  - lib/overcommit/hook/pre_commit/ruby_lint.rb
168
181
  - lib/overcommit/hook/pre_commit/scalariform.rb
@@ -197,10 +210,12 @@ files:
197
210
  - lib/overcommit/hook/pre_rebase/merged_commits.rb
198
211
  - lib/overcommit/hook/shared/bower_install.rb
199
212
  - lib/overcommit/hook/shared/bundle_install.rb
213
+ - lib/overcommit/hook/shared/composer_install.rb
200
214
  - lib/overcommit/hook/shared/index_tags.rb
201
215
  - lib/overcommit/hook/shared/npm_install.rb
202
216
  - lib/overcommit/hook/shared/rake_target.rb
203
217
  - lib/overcommit/hook/shared/submodule_status.rb
218
+ - lib/overcommit/hook/shared/yarn_install.rb
204
219
  - lib/overcommit/hook_context.rb
205
220
  - lib/overcommit/hook_context/base.rb
206
221
  - lib/overcommit/hook_context/commit_msg.rb
@@ -251,7 +266,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
266
  requirements:
252
267
  - - ">="
253
268
  - !ruby/object:Gem::Version
254
- version: '2'
269
+ version: '2.1'
255
270
  required_rubygems_version: !ruby/object:Gem::Requirement
256
271
  requirements:
257
272
  - - ">="
@@ -259,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
274
  version: '0'
260
275
  requirements: []
261
276
  rubyforge_project:
262
- rubygems_version: 2.6.12
277
+ rubygems_version: 2.6.13
263
278
  signing_key:
264
279
  specification_version: 4
265
280
  summary: Git hook manager