-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support loading Overcommit hooks supplied by Gems in the same fashion as hooks that can be provided in Repo-Specific hooks.
- Loading branch information
Showing
11 changed files
with
333 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Overcommit::HookLoader | ||
# Responsible for loading custom hooks that users install via Gems | ||
class GemHookLoader < Base | ||
def load_hooks | ||
@config.enabled_gem_hooks(@context).map do |hook_name| | ||
underscored_hook_name = Overcommit::Utils.snake_case(hook_name) | ||
require "overcommit/hook/#{@context.hook_type_name}/#{underscored_hook_name}" | ||
create_hook(hook_name) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Overcommit::HookLoader::GemHookLoader do | ||
let(:hash) { {} } | ||
let(:config) { Overcommit::Configuration.new(hash) } | ||
let(:logger) { double('logger') } | ||
let(:context) { double('context') } | ||
let(:loader) { described_class.new(config, context, logger) } | ||
|
||
describe '#load_hooks' do | ||
subject(:load_hooks) { loader.send(:load_hooks) } | ||
|
||
before do | ||
context.stub(hook_class_name: 'PreCommit', | ||
hook_type_name: 'pre_commit') | ||
end | ||
|
||
it 'loads enabled gem hooks' do | ||
allow(config).to receive(:enabled_gem_hooks).with(context).and_return(['MyCustomHook']) | ||
|
||
allow(loader).to receive(:require). | ||
with('overcommit/hook/pre_commit/my_custom_hook'). | ||
and_return(true) | ||
allow(loader).to receive(:create_hook).with('MyCustomHook') | ||
expect(loader).to receive(:require).with('overcommit/hook/pre_commit/my_custom_hook') | ||
load_hooks | ||
end | ||
end | ||
end |
Oops, something went wrong.