overcommit 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e46e06664c4b84241863650f3b1c0d0316f9c66b
4
- data.tar.gz: 16c1e91603f5c6e3aef1316cd4a1aaeb60998eef
3
+ metadata.gz: 7d0cda7604db99089da1104e74e50dddb00119f6
4
+ data.tar.gz: 97ac88f0a6772146b35cbc5e4cf93e1a16a6a024
5
5
  SHA512:
6
- metadata.gz: 7629c771c3a572032c7036af72799a0b3127fca7386d804c3fdb8609c766134853385564faa7c49296b86add33f7fe2de3ee339cdd814868c7f7cdc4142cd4f2
7
- data.tar.gz: db1da032a04d2673e2b10875ea9e0e3fa9b0b6a7afe4af780ad5eb32f6e94b3f0531636d642ffb451cb01a850a7405178a7de248b8bbb7dea7307a5f91ad5753
6
+ metadata.gz: 92478e619197b1707b9646f809c8fa0bc102f6fb44106015f91e32e4707b6585518c0d41ede75ed17bee6dfb27aaf3c52cd64fafd9ea1e80180a67362d1a5503
7
+ data.tar.gz: 7b9cdc771310e3b140f254d7bf7b0472f9e5b5587627584bf140f7fed2fcd72fbf8312da85138909f12677bbf904105850d8db89e3e10b11fdef7d6928e3a53f
@@ -785,6 +785,16 @@ PreCommit:
785
785
  - '**/*.yaml'
786
786
  - '**/*.yml'
787
787
 
788
+ YarnCheck:
789
+ enabled: false
790
+ description: 'Check yarn.lock dependencies'
791
+ required_executable: 'yarn'
792
+ flags: ['check', '--silent', '--no-progress', '--non-interactive']
793
+ install_command: 'npm install --global yarn'
794
+ include:
795
+ - 'package.json'
796
+ - 'yarn.lock'
797
+
788
798
  # Hooks that run after HEAD changes or a file is explicitly checked out.
789
799
  PostCheckout:
790
800
  ALL:
@@ -822,6 +832,12 @@ PostCheckout:
822
832
  flags: ['install']
823
833
  include: 'composer.json'
824
834
 
835
+ GitLfs:
836
+ enabled: false
837
+ description: 'Check status of lockable files tracked by Git LFS'
838
+ required_executable: 'git-lfs'
839
+ install_command: 'brew install git-lfs'
840
+
825
841
  IndexTags:
826
842
  enabled: false
827
843
  description: 'Generate tags file from source'
@@ -906,6 +922,12 @@ PostCommit:
906
922
  flags: ['HEAD~', 'HEAD']
907
923
  install_command: 'npm install -g git-guilt'
908
924
 
925
+ GitLfs:
926
+ enabled: false
927
+ description: 'Check status of lockable files tracked by Git LFS'
928
+ required_executable: 'git-lfs'
929
+ install_command: 'brew install git-lfs'
930
+
909
931
  IndexTags:
910
932
  enabled: false
911
933
  description: 'Generate tags file from source'
@@ -974,6 +996,12 @@ PostMerge:
974
996
  flags: ['install']
975
997
  include: 'composer.json'
976
998
 
999
+ GitLfs:
1000
+ enabled: false
1001
+ description: 'Check status of lockable files tracked by Git LFS'
1002
+ required_executable: 'git-lfs'
1003
+ install_command: 'brew install git-lfs'
1004
+
977
1005
  IndexTags:
978
1006
  enabled: false
979
1007
  description: 'Generate tags file from source'
@@ -1082,6 +1110,32 @@ PrePush:
1082
1110
  required: false
1083
1111
  quiet: false
1084
1112
 
1113
+ Brakeman:
1114
+ enabled: false
1115
+ description: 'Check for security vulnerabilities'
1116
+ required_executable: 'brakeman'
1117
+ flags: ['--exit-on-warn', '--quiet', '--summary']
1118
+ install_command: 'gem install brakeman'
1119
+
1120
+ GitLfs:
1121
+ enabled: false
1122
+ description: 'Upload files tracked by Git LFS'
1123
+ required_executable: 'git-lfs'
1124
+ install_command: 'brew install git-lfs'
1125
+
1126
+ Minitest:
1127
+ enabled: false
1128
+ description: 'Run Minitest test suite'
1129
+ command: ['ruby', '-Ilib:test', '-rminitest', "-e 'exit! Minitest.run'"]
1130
+ include: 'test/**/*_test.rb'
1131
+
1132
+ PhpUnit:
1133
+ enabled: false
1134
+ description: 'Run PhpUnit test suite'
1135
+ command: 'vendor/bin/phpunit'
1136
+ flags: ['--bootstrap', 'vendor/autoload.php', 'tests']
1137
+ install_command: 'composer require --dev phpunit/phpunit'
1138
+
1085
1139
  ProtectedBranches:
1086
1140
  enabled: false
1087
1141
  description: 'Check for illegal pushes to protected branches'
@@ -1115,28 +1169,11 @@ PrePush:
1115
1169
  required_executable: 'rake'
1116
1170
  install_command: 'gem install rake'
1117
1171
 
1118
- Minitest:
1119
- enabled: false
1120
- description: 'Run Minitest test suite'
1121
- command: ['ruby', '-Ilib:test', '-rminitest', "-e 'exit! Minitest.run'"]
1122
- include: 'test/**/*_test.rb'
1123
-
1124
1172
  TestUnit:
1125
1173
  enabled: false
1126
1174
  description: 'Run Test::Unit test suite'
1127
1175
  command: ['ruby', '-Ilib:test', '-rtest/unit', "-e 'exit! Test::Unit::AutoRunner.run'"]
1128
1176
 
1129
- Brakeman:
1130
- enabled: false
1131
- description: 'Check for security vulnerabilities'
1132
- required_executable: 'brakeman'
1133
- flags: ['--exit-on-warn', '--quiet', '--summary']
1134
- install_command: 'gem install brakeman'
1135
-
1136
- GitLfs:
1137
- enabled: false
1138
- description: 'Upload files tracked by Git LFS'
1139
-
1140
1177
  # Hooks that run during `git rebase`, before any commits are rebased.
1141
1178
  # If a hook fails, the rebase is aborted.
1142
1179
  PreRebase:
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Check if local yarn.lock matches package.json when either changes, unless
5
+ # yarn.lock is ignored by git.
6
+ #
7
+ # @see https://yarnpkg.com/en/docs/cli/check
8
+ class YarnCheck < Base
9
+ LOCK_FILE = 'yarn.lock'.freeze
10
+
11
+ # A lot of the errors returned by `yarn check` are outside the developer's control
12
+ # (are caused by bad package specification, in the hands of the upstream maintainer)
13
+ # So limit reporting to errors the developer can do something about
14
+ ACTIONABLE_ERRORS = [
15
+ 'Lockfile does not contain pattern'.freeze,
16
+ ].freeze
17
+
18
+ def run
19
+ # Ignore if yarn.lock is not tracked by git
20
+ ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
21
+ return :pass if ignored_files.include?(LOCK_FILE)
22
+
23
+ previous_lockfile = File.exist?(LOCK_FILE) ? File.read(LOCK_FILE) : nil
24
+ result = execute(command)
25
+ new_lockfile = File.exist?(LOCK_FILE) ? File.read(LOCK_FILE) : nil
26
+
27
+ # `yarn check` also throws many warnings, which should be ignored here
28
+ errors_regex = Regexp.new("^error (.*)(#{ACTIONABLE_ERRORS.join('|')})(.*)$")
29
+ errors = errors_regex.match(result.stderr)
30
+ unless errors.nil? && previous_lockfile == new_lockfile
31
+ return :fail, "#{LOCK_FILE} is not up-to-date -- run `yarn install`"
32
+ end
33
+
34
+ :pass
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PrePush
2
+ # Runs `phpunit` test suite before push
3
+ #
4
+ # @see https://phpunit.de/
5
+ class PhpUnit < 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
@@ -102,6 +102,13 @@ module Overcommit::HookContext
102
102
  @input_lines ||= input_string.split("\n")
103
103
  end
104
104
 
105
+ # Returns a message to display on failure.
106
+ #
107
+ # @return [String]
108
+ def post_fail_message
109
+ nil
110
+ end
111
+
105
112
  private
106
113
 
107
114
  def filter_modified_files(modified_files)
@@ -31,6 +31,10 @@ module Overcommit::HookContext
31
31
  @args[0]
32
32
  end
33
33
 
34
+ def post_fail_message
35
+ "Failed commit message:\n" + commit_message_lines.join
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def raw_commit_message_lines
@@ -18,9 +18,14 @@ module Overcommit::HookContext
18
18
  end
19
19
 
20
20
  def modified_files
21
- @modified_files ||= Overcommit::GitRepo.modified_files(
22
- refs: "#{pushed_refs[0].remote_sha1}..#{pushed_refs[0].local_sha1}"
23
- )
21
+ @modified_files ||= pushed_refs.map(&:modified_files).flatten.uniq
22
+ end
23
+
24
+ def modified_lines_in_file(file)
25
+ @modified_lines ||= {}
26
+ @modified_lines[file] = pushed_refs.each_with_object(Set.new) do |pushed_ref, set|
27
+ set.merge(pushed_ref.modified_lines_in_file(file))
28
+ end
24
29
  end
25
30
 
26
31
  PushedRef = Struct.new(:local_ref, :local_sha1, :remote_ref, :remote_sha1) do
@@ -40,12 +45,24 @@ module Overcommit::HookContext
40
45
  deleted? || forced?
41
46
  end
42
47
 
48
+ def modified_files
49
+ Overcommit::GitRepo.modified_files(refs: ref_range)
50
+ end
51
+
52
+ def modified_lines_in_file(file)
53
+ Overcommit::GitRepo.extract_modified_lines(file, refs: ref_range)
54
+ end
55
+
43
56
  def to_s
44
57
  "#{local_ref} #{local_sha1} #{remote_ref} #{remote_sha1}"
45
58
  end
46
59
 
47
60
  private
48
61
 
62
+ def ref_range
63
+ "#{remote_sha1}..#{local_sha1}"
64
+ end
65
+
49
66
  def overwritten_commits
50
67
  return @overwritten_commits if defined? @overwritten_commits
51
68
  result = Overcommit::Subprocess.spawn(%W[git rev-list #{remote_sha1} ^#{local_sha1}])
@@ -51,7 +51,7 @@ module Overcommit
51
51
 
52
52
  attr_reader :log
53
53
 
54
- def run_hooks
54
+ def run_hooks # rubocop:disable Metrics/MethodLength
55
55
  if @hooks.any?(&:enabled?)
56
56
  @printer.start_run
57
57
 
@@ -74,7 +74,14 @@ module Overcommit
74
74
 
75
75
  print_results
76
76
 
77
- !(@failed || @interrupted)
77
+ hook_failed = @failed || @interrupted
78
+
79
+ if hook_failed
80
+ message = @context.post_fail_message
81
+ @printer.hook_run_failed(message) unless message.nil?
82
+ end
83
+
84
+ !hook_failed
78
85
  else
79
86
  @printer.nothing_to_run
80
87
  true # Run was successful
@@ -75,6 +75,12 @@ module Overcommit
75
75
  end
76
76
  end
77
77
 
78
+ def hook_run_failed(message)
79
+ log.newline
80
+ log.log message
81
+ log.newline
82
+ end
83
+
78
84
  private
79
85
 
80
86
  def print_header(hook)
@@ -125,9 +131,7 @@ module Overcommit
125
131
  self.class.__send__(:alias_method, old_method, method_name)
126
132
 
127
133
  self.class.send(:define_method, new_method) do |*args|
128
- @lock.synchronize do
129
- __send__(old_method, *args)
130
- end
134
+ @lock.synchronize { __send__(old_method, *args) }
131
135
  end
132
136
 
133
137
  self.class.__send__(:alias_method, method_name, new_method)
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.42.0'.freeze
5
+ VERSION = '0.43.0'.freeze
6
6
  end
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.42.0
4
+ version: 0.43.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: 2018-01-30 00:00:00.000000000 Z
12
+ date: 2018-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -196,10 +196,11 @@ files:
196
196
  - lib/overcommit/hook/pre_commit/xml_syntax.rb
197
197
  - lib/overcommit/hook/pre_commit/yaml_lint.rb
198
198
  - lib/overcommit/hook/pre_commit/yaml_syntax.rb
199
+ - lib/overcommit/hook/pre_commit/yarn_check.rb
199
200
  - lib/overcommit/hook/pre_push/base.rb
200
201
  - lib/overcommit/hook/pre_push/brakeman.rb
201
- - lib/overcommit/hook/pre_push/git_lfs.rb
202
202
  - lib/overcommit/hook/pre_push/minitest.rb
203
+ - lib/overcommit/hook/pre_push/php_unit.rb
203
204
  - lib/overcommit/hook/pre_push/protected_branches.rb
204
205
  - lib/overcommit/hook/pre_push/pytest.rb
205
206
  - lib/overcommit/hook/pre_push/python_nose.rb
@@ -274,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
275
  version: '0'
275
276
  requirements: []
276
277
  rubyforge_project:
277
- rubygems_version: 2.6.13
278
+ rubygems_version: 2.5.1
278
279
  signing_key:
279
280
  specification_version: 4
280
281
  summary: Git hook manager
@@ -1,20 +0,0 @@
1
- module Overcommit::Hook::PrePush
2
- # Invokes Git LFS command that uploads files tracked by Git LFS to the LFS storage
3
- #
4
- # @see https://git-lfs.github.com/
5
- class GitLfs < Base
6
- def run
7
- unless in_path?('git-lfs')
8
- return :warn, 'This repository is configured for Git LFS but \'git-lfs\' ' \
9
- "was not found on your path.\nIf you no longer wish to use Git LFS, " \
10
- 'disable this hook by removing or setting \'enabled: false\' for GitLFS ' \
11
- 'hook in your .overcommit.yml file'
12
- end
13
-
14
- result = execute(['git', 'lfs', 'pre-push', remote_name, remote_url])
15
- return :fail, result.stderr unless result.success?
16
-
17
- :pass
18
- end
19
- end
20
- end