Commit eff5746b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Redesign plugins system

Signed-off-by: Dmitriy Zaporozhets's avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 5bb435d0
......@@ -12,14 +12,7 @@ class SystemHooksService
hook.async_execute(data, 'system_hooks')
end
# Execute external plugins
Gitlab::Plugin.all.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
Gitlab::Plugin.execute_all_async(data)
end
private
......
class PluginWorker
include ApplicationWorker
sidekiq_options retry: false
def perform(file_name, data)
Gitlab::Plugin.execute(file_name, data)
end
end
module Gitlab
module Plugin
def self.all
files.map do |file|
file_name = File.basename(file, '.rb')
def self.files
Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
end
# 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 validation check"
klass
end
def self.execute_all_async(data)
files.each do |file|
PluginWorker.perform_async(file, data)
end
end
def self.files
Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
def self.execute(file, data)
# TODO: Implement
#
# Reuse some code from gitlab-shell https://gitlab.com/gitlab-org/gitlab-shell/blob/master/lib/gitlab_custom_hook.rb#L40
# Pass data as STDIN (or JSON encode?)
#
# 1. Return true if 0 exit code
# 2. Return false if non-zero exit code
end
end
end
......@@ -27,13 +27,13 @@ namespace :plugins do
task validate: :environment do
puts 'Validating plugins from /plugins directory'
Gitlab::Plugin.all.each do |plugin|
begin
plugin.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
rescue => e
puts "- #{plugin} raised an exception during boot check. #{e}"
Gitlab::Plugin.files.each do |file|
result = Gitlab::Plugin.execute(file, Gitlab::DataBuilder::Push::SAMPLE_DATA)
if result
puts "* #{file} succeed (zero exit code)"
else
puts "- #{plugin} passed validation check"
puts "* #{file} failure (non-zero exit code)"
end
end
end
......
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