Add external plugins support to extend system hooks
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
1ffa07e6f3
commit
9be0c2734a
3 changed files with 39 additions and 0 deletions
|
@ -11,6 +11,15 @@ class SystemHooksService
|
||||||
SystemHook.hooks_for(hooks_scope).find_each do |hook|
|
SystemHook.hooks_for(hooks_scope).find_each do |hook|
|
||||||
hook.async_execute(data, 'system_hooks')
|
hook.async_execute(data, 'system_hooks')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Execute external plugins
|
||||||
|
PLUGINS.each do |plugin|
|
||||||
|
begin
|
||||||
|
plugin.new.execute(data)
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.warn("GitLab -> Plugins -> #{plugin.class.name} raised an axception during execution. #{e}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -28,6 +28,7 @@ module Gitlab
|
||||||
config.eager_load_paths.push(*%W[#{config.root}/lib
|
config.eager_load_paths.push(*%W[#{config.root}/lib
|
||||||
#{config.root}/app/models/hooks
|
#{config.root}/app/models/hooks
|
||||||
#{config.root}/app/models/members
|
#{config.root}/app/models/members
|
||||||
|
#{config.root}/plugins
|
||||||
#{config.root}/app/models/project_services
|
#{config.root}/app/models/project_services
|
||||||
#{config.root}/app/workers/concerns
|
#{config.root}/app/workers/concerns
|
||||||
#{config.root}/app/services/concerns
|
#{config.root}/app/services/concerns
|
||||||
|
|
29
config/initializers/9_plugins.rb
Normal file
29
config/initializers/9_plugins.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
class PluginsSystem
|
||||||
|
attr_accessor :plugins, :files
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@files = Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_plugins
|
||||||
|
files.map do |file|
|
||||||
|
file_name = File.basename(file, '.rb')
|
||||||
|
|
||||||
|
# Just give sample data to method and expect it to not crash.
|
||||||
|
begin
|
||||||
|
klass = Object.const_get(file_name.classify)
|
||||||
|
klass.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.warn("GitLab -> Plugins -> #{file_name} raised an exception during boot check. #{e}")
|
||||||
|
next
|
||||||
|
else
|
||||||
|
Rails.logger.info "GitLab -> Plugins -> #{file_name} passed boot check"
|
||||||
|
klass
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Load external plugins from /plugins directory
|
||||||
|
# and set into PLUGINS variable
|
||||||
|
PLUGINS = PluginsSystem.new.valid_plugins
|
Loading…
Reference in a new issue