rails_git_hooks 0.6.1 → 0.7.1
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 +4 -4
- data/CHANGELOG.md +30 -2
- data/README.md +149 -83
- data/lib/rails_git_hooks/checks/base.rb +55 -0
- data/lib/rails_git_hooks/checks/commit_msg/jira_prefix.rb +31 -0
- data/lib/rails_git_hooks/checks/commit_msg.rb +10 -0
- data/lib/rails_git_hooks/checks/pre_commit/debugger_check.rb +43 -0
- data/lib/rails_git_hooks/checks/pre_commit/default_branch.rb +20 -0
- data/lib/rails_git_hooks/checks/pre_commit/json_format_check.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/migrations_check.rb +37 -0
- data/lib/rails_git_hooks/checks/pre_commit/rubocop.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/whitespace_check.rb +31 -0
- data/lib/rails_git_hooks/checks/pre_commit/yaml_format_check.rb +31 -0
- data/lib/rails_git_hooks/checks/pre_commit.rb +16 -0
- data/lib/rails_git_hooks/checks/pre_push/run_tests.rb +24 -0
- data/lib/rails_git_hooks/checks/pre_push.rb +10 -0
- data/lib/rails_git_hooks/checks.rb +6 -0
- data/lib/rails_git_hooks/cli.rb +85 -64
- data/lib/rails_git_hooks/config/constants.rb +20 -0
- data/lib/rails_git_hooks/config/defaults.yml +127 -0
- data/lib/rails_git_hooks/config/defaults_loader.rb +42 -0
- data/lib/rails_git_hooks/core/check_definition.rb +63 -0
- data/lib/rails_git_hooks/core/check_result.rb +41 -0
- data/lib/rails_git_hooks/core/error.rb +5 -0
- data/lib/rails_git_hooks/install/installer.rb +53 -0
- data/lib/rails_git_hooks/runtime/check_registry.rb +29 -0
- data/lib/rails_git_hooks/runtime/dependency_checker.rb +51 -0
- data/lib/rails_git_hooks/runtime/file_matcher.rb +23 -0
- data/lib/rails_git_hooks/runtime/override_config.rb +125 -0
- data/lib/rails_git_hooks/runtime/policy_resolver.rb +36 -0
- data/lib/rails_git_hooks/runtime/repository.rb +61 -0
- data/lib/rails_git_hooks/runtime/runner.rb +76 -0
- data/lib/rails_git_hooks/runtime.rb +25 -0
- data/lib/rails_git_hooks/version.rb +1 -1
- data/lib/rails_git_hooks.rb +14 -5
- data/templates/hooks/commit-msg +13 -0
- data/templates/hooks/pre-commit +13 -0
- data/templates/hooks/pre-push +13 -0
- metadata +33 -5
- data/lib/rails_git_hooks/installer.rb +0 -118
- data/lib/rails_git_hooks/templates/commit-msg +0 -32
- data/lib/rails_git_hooks/templates/pre-commit +0 -58
- data/lib/rails_git_hooks/templates/pre-push +0 -21
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
# Runs RuboCop on staged .rb files. Commit is aborted if RuboCop reports offenses.
|
|
6
|
-
|
|
7
|
-
# Git runs hooks with CWD = repo root; find .git from here
|
|
8
|
-
repo_root = Dir.pwd
|
|
9
|
-
git_dir = File.join(repo_root, '.git')
|
|
10
|
-
git_dir = File.expand_path(File.read(git_dir).strip.sub(/\Agitdir: \s*/, ''), repo_root) if File.file?(git_dir)
|
|
11
|
-
disabled_file = File.join(git_dir, 'rails_git_hooks_disabled')
|
|
12
|
-
if File.exist?(disabled_file)
|
|
13
|
-
disabled = File.read(disabled_file).split("\n").map(&:strip)
|
|
14
|
-
exit 0 if disabled.include?('*') || disabled.include?('pre-commit')
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Trailing whitespace / conflict markers check (disabled by default; enable with .git/rails_git_hooks_whitespace_check)
|
|
18
|
-
whitespace_check_file = File.join(git_dir, 'rails_git_hooks_whitespace_check')
|
|
19
|
-
if File.exist?(whitespace_check_file)
|
|
20
|
-
staged = `git diff --cached --name-only`.split("\n").map(&:strip).reject(&:empty?)
|
|
21
|
-
errors = []
|
|
22
|
-
staged.each do |path|
|
|
23
|
-
next unless File.file?(path)
|
|
24
|
-
|
|
25
|
-
File.read(path).lines.each_with_index do |line, i|
|
|
26
|
-
errors << "#{path}:#{i + 1}: trailing whitespace" if line.match?(/[ \t]\z/)
|
|
27
|
-
stripped = line.strip
|
|
28
|
-
errors << "#{path}:#{i + 1}: conflict marker" if stripped.start_with?('<<<<<<<', '=======', '>>>>>>>')
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
unless errors.empty?
|
|
32
|
-
warn 'Commit rejected (whitespace/conflict check):'
|
|
33
|
-
errors.uniq.each { |e| warn " #{e}" }
|
|
34
|
-
exit 1
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Prevent commits on default branch (master/main)
|
|
39
|
-
branch = `git rev-parse --abbrev-ref HEAD`.strip
|
|
40
|
-
if %w[master main].include?(branch)
|
|
41
|
-
warn "Commits on '#{branch}' are not allowed. Create a feature branch."
|
|
42
|
-
exit 1
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
require 'english'
|
|
46
|
-
require 'rubocop'
|
|
47
|
-
|
|
48
|
-
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
|
|
49
|
-
|
|
50
|
-
changed_files = `git status --porcelain`.split(/\n/)
|
|
51
|
-
.select { |file_name_with_status| file_name_with_status =~ ADDED_OR_MODIFIED }
|
|
52
|
-
.map { |file_name_with_status| file_name_with_status.split(' ')[1] }
|
|
53
|
-
.select { |file_name| File.extname(file_name) == '.rb' }
|
|
54
|
-
.join(' ')
|
|
55
|
-
|
|
56
|
-
system("rubocop #{changed_files}") unless changed_files.empty?
|
|
57
|
-
|
|
58
|
-
exit $CHILD_STATUS.to_s[-1].to_i
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
# Runs the full test suite before push. Push is aborted if tests fail.
|
|
6
|
-
# Uses `bundle exec rspec`. For Minitest, edit to use `bundle exec rake test`.
|
|
7
|
-
|
|
8
|
-
# Git runs hooks with CWD = repo root; find .git from here
|
|
9
|
-
repo_root = Dir.pwd
|
|
10
|
-
git_dir = File.join(repo_root, '.git')
|
|
11
|
-
git_dir = File.expand_path(File.read(git_dir).strip.sub(/\Agitdir: \s*/, ''), repo_root) if File.file?(git_dir)
|
|
12
|
-
disabled_file = File.join(git_dir, 'rails_git_hooks_disabled')
|
|
13
|
-
if File.exist?(disabled_file)
|
|
14
|
-
disabled = File.read(disabled_file).split("\n").map(&:strip)
|
|
15
|
-
exit 0 if disabled.include?('*') || disabled.include?('pre-push')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
require 'english'
|
|
19
|
-
|
|
20
|
-
system('bundle exec rspec')
|
|
21
|
-
exit $CHILD_STATUS.to_s[-1].to_i
|