Skip to content

Commit

Permalink
Merge branch 'main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sds authored Feb 25, 2024
2 parents f4c3a23 + 9c3d118 commit 7683b10
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 77 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: Lint
on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
overcommit:
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.3
bundler-cache: true

- name: Prepare environment
Expand Down
30 changes: 14 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Tests
on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
rspec:
Expand All @@ -14,22 +14,20 @@ jobs:
fail-fast: false
matrix:
ruby-version:
- '2.6'
- '2.7'
- '3.0'
- '3.1'
- "2.6"
- "2.7"
- "3.0"
- "3.1"
- "3.2"
os:
- ubuntu
- windows

# Tempfile behavior has changed on Ruby 3.1 such that tests
# fail with permission denied. Would welcome a PR with a fix.
exclude:
- ruby-version: '3.1'
os: windows
# At the moment of this commit various specs fail on Windows.
# Any contributor is welcome to fix them and enable the Windows build.
# Please see Issue #836 for more details.
# - windows

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
Expand All @@ -44,7 +42,7 @@ jobs:
bundle exec rspec
- name: Code coverage reporting
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
flag-name: ruby${{ matrix.ruby-version }}-${{ matrix.os }}
Expand All @@ -56,7 +54,7 @@ jobs:

steps:
- name: Finalize code coverage report
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.4

Expand Down
137 changes: 137 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --no-exclude-limit`
# on 2024-01-10 14:09:00 UTC using RuboCop version 1.59.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowAliasSyntax, AllowedMethods.
# AllowedMethods: alias_method, public, protected, private
Layout/EmptyLinesAroundAttributeAccessor:
Exclude:
- 'lib/overcommit/hook_context/post_merge.rb'

# Offense count: 6
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/overcommit/message_processor_spec.rb'

# Offense count: 4
Lint/MixedRegexpCaptureTypes:
Exclude:
- 'lib/overcommit/hook/pre_commit/dart_analyzer.rb'
- 'lib/overcommit/hook/pre_commit/java_checkstyle.rb'
- 'lib/overcommit/hook/pre_commit/kt_lint.rb'
- 'lib/overcommit/hook/pre_commit/scalastyle.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Lint/RedundantCopDisableDirective:
Exclude:
- 'lib/overcommit/hook_runner.rb'
- 'lib/overcommit/printer.rb'

# Offense count: 1
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
- 'lib/overcommit/utils.rb'

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Metrics/CyclomaticComplexity:
Exclude:
- 'lib/overcommit/configuration.rb'
- 'lib/overcommit/hook_runner.rb'

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Metrics/PerceivedComplexity:
Exclude:
- 'lib/overcommit/configuration.rb'
- 'lib/overcommit/configuration_validator.rb'
- 'lib/overcommit/hook_runner.rb'

# Offense count: 23
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'bin/overcommit'
- 'lib/overcommit/hook/post_commit/git_guilt.rb'
- 'template-dir/hooks/commit-msg'
- 'template-dir/hooks/overcommit-hook'
- 'template-dir/hooks/post-checkout'
- 'template-dir/hooks/post-commit'
- 'template-dir/hooks/post-merge'
- 'template-dir/hooks/post-rewrite'
- 'template-dir/hooks/pre-commit'
- 'template-dir/hooks/pre-push'
- 'template-dir/hooks/pre-rebase'
- 'template-dir/hooks/prepare-commit-msg'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformValues:
Exclude:
- 'lib/overcommit/configuration.rb'
- 'lib/overcommit/configuration_validator.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/overcommit/logger.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantBegin:
Exclude:
- 'lib/overcommit/hook/prepare_commit_msg/replace_branch.rb'
- 'lib/overcommit/utils.rb'

# Offense count: 10
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeForConstants.
Style/RedundantFetchBlock:
Exclude:
- 'lib/overcommit/configuration.rb'
- 'lib/overcommit/configuration_validator.rb'
- 'lib/overcommit/hook/base.rb'
- 'lib/overcommit/hook/pre_commit/chamber_verification.rb'
- 'lib/overcommit/logger.rb'
- 'spec/support/shell_helpers.rb'

# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpEscape:
Exclude:
- 'lib/overcommit/configuration.rb'
- 'lib/overcommit/hook/pre_commit/php_cs.rb'
- 'lib/overcommit/hook/pre_commit/php_lint.rb'
- 'lib/overcommit/hook/pre_commit/php_stan.rb'

# Offense count: 15
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'lib/overcommit/hook/pre_commit/bundle_check.rb'
- 'lib/overcommit/hook_runner.rb'
- 'lib/overcommit/message_processor.rb'
- 'spec/integration/gemfile_option_spec.rb'
- 'spec/overcommit/hook/commit_msg/text_width_spec.rb'
- 'spec/overcommit/hook/prepare_commit_msg/base_spec.rb'
- 'spec/overcommit/message_processor_spec.rb'
- 'spec/spec_helper.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ZeroLengthPredicate:
Exclude:
- 'lib/overcommit/hook/pre_commit/ruby_syntax.rb'
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Overcommit Changelog

## 0.62.0

* Allow version 5 of `childprocess` gem dependency

## 0.61.0

* Allow `ReplaceBranch` to use `skip_if`
* Fix local Overcommit file merges with existing `.overcommit.yml`

## 0.60.0

* Allow overriding `Gemfile.lock` location for `BundleCheck` pre-commit hook
Expand Down
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ gem 'rspec', '~> 3.0'
gem 'simplecov', '~> 0.21.0'
gem 'simplecov-lcov', '~> 0.8.0'

# Pin RuboCop for Travis builds.
gem 'rubocop', '0.82.0'
# Pin RuboCop for CI builds
if RUBY_VERSION < '2.7.0'
gem 'rubocop', '1.50.0'
else
gem 'rubocop', '1.59.0'
end

gem 'ffi' if Gem.win_platform?
6 changes: 2 additions & 4 deletions lib/overcommit/configuration_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ def load_repo_config
# Loads a configuration, ensuring it extends the default configuration.
def load_file(file, local_file = nil)
overcommit_config = self.class.load_from_file(file, default: false, logger: @log)
if local_file
local_config = self.class.load_from_file(local_file, default: false, logger: @log)
end
l_config = self.class.load_from_file(local_file, default: false, logger: @log) if local_file
config = self.class.default_configuration.merge(overcommit_config)
config = self.class.default_configuration.merge(local_config) if local_config
config = config.merge(l_config) if l_config

if @options.fetch(:verify) { config.verify_signatures? }
verify_signatures(config)
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def schema_files
end

def schema
@schema ||= schema_files.map { |file| File.read(file, encoding) }.join
@schema ||= schema_files.map { |file| File.read(file, **(encoding || {})) }.join
@schema.tr('_', '')
end

Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Defines the gem version.
module Overcommit
VERSION = '0.60.0'
VERSION = '0.62.0'
end
2 changes: 1 addition & 1 deletion overcommit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |s|

s.required_ruby_version = '>= 2.4'

s.add_dependency 'childprocess', '>= 0.6.3', '< 5'
s.add_dependency 'childprocess', '>= 0.6.3', '< 6'
s.add_dependency 'iniparse', '~> 1.4'
s.add_dependency 'rexml', '~> 3.2'
end
62 changes: 43 additions & 19 deletions spec/overcommit/configuration_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,32 @@
end
end

context 'when repo contains a local configuration file' do
context 'when repo only contains a repo level configuration file' do
let(:config_contents) { <<-CFG }
plugin_directory: 'some-directory'
PreCommit:
Rubocop:
enabled: true
CFG

around do |example|
repo do
File.open('.overcommit.yml', 'w') { |f| f.write(config_contents) }
example.run
end
end

it 'includes default settings' do
subject
subject.for_hook('CapitalizedSubject', 'CommitMsg').should include('enabled' => true)
end

it 'includes .overwrite.yml configs' do
subject
subject.for_hook('Rubocop', 'PreCommit').should include('enabled' => true)
end
end

context 'when repo also contains a local configuration file' do
let(:local_config_contents) { <<-CFG }
plugin_directory: 'some-different-directory'
CFG
Expand All @@ -75,28 +96,31 @@
end
end

it 'loads the file' do
Overcommit::ConfigurationLoader.any_instance.
should_receive(:load_file).
with(File.expand_path('.overcommit.yml'), File.expand_path('.local-overcommit.yml'))
let(:config_contents) { <<-CFG }
PreCommit:
ScssLint:
enabled: true
CFG

let(:local_config_contents) { <<-CFG }
PreCommit:
Rubocop:
enabled: true
CFG

it 'includes default settings' do
subject
subject.for_hook('CapitalizedSubject', 'CommitMsg').should include('enabled' => true)
end

it 'merges each loaded file with the default configuration' do
subject.plugin_directory.should == File.expand_path('some-different-directory')
it 'includes .overwrite.yml configs' do
subject
subject.for_hook('ScssLint', 'PreCommit').should include('enabled' => true)
end

context 'and the configuration file contains a hook with no `enabled` option' do
let(:config_contents) { <<-CFG }
PreCommit:
ScssLint:
command: ['bundle', 'exec', 'scss-lint']
CFG

it 'displays a warning' do
subject
output.string.should =~ /PreCommit::ScssLint.*not.*enabled/i
end
it 'includes .local-overwrite.yml configs' do
subject
subject.for_hook('Rubocop', 'PreCommit').should include('enabled' => true)
end
end
end
Expand Down
Loading

0 comments on commit 7683b10

Please sign in to comment.