summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-19 19:55:54 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-26 16:06:49 +0200
commiteff5746b5e7cf4075edd6d1c76fdcd24c1603bb4 (patch)
tree368bb9935f8cf3f6cbcf20c48c9f48e3456a96a2 /lib
parent5bb435d0e75ad84e2fc379208cc36a25a4574453 (diff)
downloadgitlab-ce-eff5746b5e7cf4075edd6d1c76fdcd24c1603bb4.tar.gz
Redesign plugins system
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/plugin.rb30
-rw-r--r--lib/tasks/plugins.rake12
2 files changed, 20 insertions, 22 deletions
diff --git a/lib/gitlab/plugin.rb b/lib/gitlab/plugin.rb
index cbc57a5cce3..9604cac4b20 100644
--- a/lib/gitlab/plugin.rb
+++ b/lib/gitlab/plugin.rb
@@ -1,25 +1,23 @@
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
diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake
index 8728e232c9c..9c9f1fece85 100644
--- a/lib/tasks/plugins.rake
+++ b/lib/tasks/plugins.rake
@@ -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