summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-08 17:51:02 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-26 16:06:49 +0200
commit9be0c2734ae3e3cc84196cf167a0c327c7cf8570 (patch)
tree0a91f56279321052ce8e91c906f9317f0901756b /config
parent1ffa07e6f35fb7832ba8c6fd764da6c201e521bd (diff)
downloadgitlab-ce-9be0c2734ae3e3cc84196cf167a0c327c7cf8570.tar.gz
Add external plugins support to extend system hooks
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'config')
-rw-r--r--config/application.rb1
-rw-r--r--config/initializers/9_plugins.rb29
2 files changed, 30 insertions, 0 deletions
diff --git a/config/application.rb b/config/application.rb
index 918bd4d57cf..f2fc6270748 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -28,6 +28,7 @@ module Gitlab
config.eager_load_paths.push(*%W[#{config.root}/lib
#{config.root}/app/models/hooks
#{config.root}/app/models/members
+ #{config.root}/plugins
#{config.root}/app/models/project_services
#{config.root}/app/workers/concerns
#{config.root}/app/services/concerns
diff --git a/config/initializers/9_plugins.rb b/config/initializers/9_plugins.rb
new file mode 100644
index 00000000000..9f252ccd296
--- /dev/null
+++ b/config/initializers/9_plugins.rb
@@ -0,0 +1,29 @@
+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