Remove plugin initializer and add plugins:validate rake task
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
b985fe95b6
commit
5bb435d0e7
4 changed files with 41 additions and 30 deletions
|
@ -13,7 +13,7 @@ class SystemHooksService
|
|||
end
|
||||
|
||||
# Execute external plugins
|
||||
PLUGINS.each do |plugin|
|
||||
Gitlab::Plugin.all.each do |plugin|
|
||||
begin
|
||||
plugin.new.execute(data)
|
||||
rescue => e
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
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
|
25
lib/gitlab/plugin.rb
Normal file
25
lib/gitlab/plugin.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
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
|
|||
puts "Failed to save #{file_path}."
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue