Commit e8985f2f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Remove plugin initializer and add plugins:validate rake task

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 08c56dcc
...@@ -15,7 +15,7 @@ class SystemHooksService ...@@ -15,7 +15,7 @@ class SystemHooksService
end end
# Execute external plugins # Execute external plugins
PLUGINS.each do |plugin| Gitlab::Plugin.all.each do |plugin|
begin begin
plugin.new.execute(data) plugin.new.execute(data)
rescue => e rescue => e
......
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
module Gitlab
module Plugin
def self.all
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 validation check"
klass
end
end
end
def self.files
Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
end
end
end
...@@ -22,4 +22,19 @@ namespace :plugins do ...@@ -22,4 +22,19 @@ namespace :plugins do
puts "Failed to save #{file_path}." puts "Failed to save #{file_path}."
end end
end end
desc 'Validate existing plugins'
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}"
else
puts "- #{plugin} passed validation check"
end
end
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