Redesign plugins system
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
5bb435d0e7
commit
eff5746b5e
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
class PluginWorker
|
||||
include ApplicationWorker
|
||||
|
||||
sidekiq_options retry: false
|
||||
|
||||
def perform(file_name, data)
|
||||
Gitlab::Plugin.execute(file_name, data)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,25 +1,23 @@
|
|||
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
|
||||
|
||||
def self.execute_all_async(data)
|
||||
files.each do |file|
|
||||
PluginWorker.perform_async(file, data)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue