diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gitlab/plugin.rb | 28 | ||||
| -rw-r--r-- | lib/tasks/plugins.rake | 24 |
2 files changed, 20 insertions, 32 deletions
diff --git a/lib/gitlab/plugin.rb b/lib/gitlab/plugin.rb index 9604cac4b20..1035d258907 100644 --- a/lib/gitlab/plugin.rb +++ b/lib/gitlab/plugin.rb @@ -1,23 +1,35 @@ module Gitlab module Plugin def self.files - Dir.glob(Rails.root.join('plugins', '*_plugin.rb')) + Dir.glob(Rails.root.join('plugins/enabled/*')) end def self.execute_all_async(data) files.each do |file| + puts 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 + # Prepare the hook subprocess. Attach a pipe to its stdin, and merge + # both its stdout and stderr into our own stdout. + stdin_reader, stdin_writer = IO.pipe + hook_pid = spawn({}, file, in: stdin_reader, err: :out) + stdin_reader.close + + # Submit changes to the hook via its stdin. + begin + IO.copy_stream(StringIO.new(data.to_json), stdin_writer) + rescue Errno::EPIPE + # It is not an error if the hook does not consume all of its input. + end + + # Close the pipe to let the hook know there is no further input. + stdin_writer.close + + Process.wait(hook_pid) + $?.success? end end end diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake index 9c9f1fece85..f4d7edb2eb2 100644 --- a/lib/tasks/plugins.rake +++ b/lib/tasks/plugins.rake @@ -1,28 +1,4 @@ namespace :plugins do - desc 'Generate skeleton for new plugin' - task generate: :environment do - ARGV.each { |a| task a.to_sym { } } - name = ARGV[1] - - unless name.present? - puts 'Error. You need to specify a name for the plugin' - exit 1 - end - - class_name = name.classify - param = name.underscore - file_path = Rails.root.join('plugins', param + '_plugin.rb') - template = File.read(Rails.root.join('generator_templates', 'plugins', 'template.rb')) - template.gsub!('$NAME', class_name) - - if File.write(file_path, template) - puts "Done. Your plugin saved under #{file_path}." - puts 'Feel free to edit it.' - else - puts "Failed to save #{file_path}." - end - end - desc 'Validate existing plugins' task validate: :environment do puts 'Validating plugins from /plugins directory' |
