From b985fe95b6c30bc83725e9b5e18a79a8ceb900d3 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Thu, 8 Feb 2018 18:14:10 +0200
Subject: [PATCH] Add generator for plugins

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 generator_templates/plugins/template.rb | 16 ++++++++++++++++
 lib/tasks/plugins.rake                  | 25 +++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 generator_templates/plugins/template.rb
 create mode 100644 lib/tasks/plugins.rake

diff --git a/generator_templates/plugins/template.rb b/generator_templates/plugins/template.rb
new file mode 100644
index 000000000000..16c87f2c2b26
--- /dev/null
+++ b/generator_templates/plugins/template.rb
@@ -0,0 +1,16 @@
+# Requirements
+# * File name must end with _s.rb. For example, jenkins_plugin.rb.
+# * All code should be inside class. No code should be executed on file load.
+# * Class name must be same as file name.
+#   If file name is jenkins_plugin.rb then class name must be JenkinsPlugin.
+#
+# Reccomendations
+# * Code should not depend on or use GitLab classes and other code.
+# * Consider contributing your plugin to GitLab source code so we can test it
+#   and make sure it will work in further version.
+#
+class $NAMEPlugin
+  def execute(data)
+    # TODO: Implement me
+  end
+end
diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake
new file mode 100644
index 000000000000..fac6070ea9bc
--- /dev/null
+++ b/lib/tasks/plugins.rake
@@ -0,0 +1,25 @@
+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
+end
-- 
GitLab