Commit 9be0c273 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add external plugins support to extend system hooks

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 1ffa07e6
......@@ -11,6 +11,15 @@ class SystemHooksService
SystemHook.hooks_for(hooks_scope).find_each do |hook|
hook.async_execute(data, 'system_hooks')
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
private
......
......@@ -28,6 +28,7 @@ module Gitlab
config.eager_load_paths.push(*%W[#{config.root}/lib
#{config.root}/app/models/hooks
#{config.root}/app/models/members
#{config.root}/plugins
#{config.root}/app/models/project_services
#{config.root}/app/workers/concerns
#{config.root}/app/services/concerns
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment