summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorZJ van de Weg <zegerjan@gitlab.com>2016-05-27 11:00:56 +0200
committerAlfredo Sumaran <alfredo@gitlab.com>2016-06-20 14:48:28 -0500
commit27bf7ae59eb95bff0254b8ad3c001ea2397ec544 (patch)
tree111f9defe358890bf97926378d32ca5c2ed9f630 /lib/tasks
parent74f8f260982a9b9e1941ad803d53d229cc27c85f (diff)
downloadgitlab-ce-27bf7ae59eb95bff0254b8ad3c001ea2397ec544.tar.gz
Refactor Gitlab::Gitignores
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gitlab/update_gitignore.rake46
-rw-r--r--lib/tasks/gitlab/update_templates.rake61
2 files changed, 61 insertions, 46 deletions
diff --git a/lib/tasks/gitlab/update_gitignore.rake b/lib/tasks/gitlab/update_gitignore.rake
deleted file mode 100644
index 4fd48cccb1d..00000000000
--- a/lib/tasks/gitlab/update_gitignore.rake
+++ /dev/null
@@ -1,46 +0,0 @@
-namespace :gitlab do
- desc "GitLab | Update gitignore"
- task :update_gitignore do
- unless clone_gitignores
- puts "Cloning the gitignores failed".color(:red)
- return
- end
-
- remove_unneeded_files(gitignore_directory)
- remove_unneeded_files(global_directory)
-
- puts "Done".color(:green)
- end
-
- def clone_gitignores
- FileUtils.rm_rf(gitignore_directory) if Dir.exist?(gitignore_directory)
- FileUtils.cd vendor_directory
-
- system('git clone --depth=1 --branch=master https://github.com/github/gitignore.git')
- end
-
- # Retain only certain files:
- # - The LICENSE, because we have to
- # - The sub dir global
- # - The gitignores themself
- # - Dir.entires returns also the entries '.' and '..'
- def remove_unneeded_files(path)
- Dir.foreach(path) do |file|
- FileUtils.rm_rf(File.join(path, file)) unless file =~ /(\.{1,2}|LICENSE|Global|\.gitignore)\z/
- end
- end
-
- private
-
- def vendor_directory
- Rails.root.join('vendor')
- end
-
- def gitignore_directory
- File.join(vendor_directory, 'gitignore')
- end
-
- def global_directory
- File.join(gitignore_directory, 'Global')
- end
-end
diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake
new file mode 100644
index 00000000000..36ffad8aae9
--- /dev/null
+++ b/lib/tasks/gitlab/update_templates.rake
@@ -0,0 +1,61 @@
+namespace :gitlab do
+ desc "GitLab | Update templates"
+ task :update_templates do
+ update("gitignore")
+ update("gitlab-ci-yml")
+ end
+
+ def update(directory)
+ unless clone_repository(directory)
+ puts "Cloning the #{directory} templates failed".red
+ return
+ end
+
+ remove_unneeded_files(directory)
+ puts "Done".green
+ end
+
+ def clone_repository(directory)
+ dir = File.join(vendor_directory, directory)
+ FileUtils.rm_rf(dir) if Dir.exist?(dir)
+ FileUtils.cd vendor_directory
+
+ system("git clone --depth=1 --branch=master #{TEMPLATE_DATA[directory]}")
+ end
+
+ # Retain only certain files:
+ # - The LICENSE, because we have to
+ # - The sub dir global
+ # - The gitignores themself
+ # - Dir.entires returns also the entries '.' and '..'
+ def remove_unneeded_files(directory)
+ regex = CLEANUP_REGEX[directory]
+ Dir.foreach(directory) do |file|
+ FileUtils.rm_rf(File.join(directory, file)) unless file =~ regex
+ end
+ end
+
+ private
+
+ TEMPLATE_DATA = {
+ "gitignore" => "https://github.com/github/gitignore.git",
+ "gitlab-ci-yml" => "https://gitlab.com/gitlab-org/gitlab-ci-yml.git"
+ }.freeze
+
+ CLEANUP_REGEX = {
+ "gitignore" => /(\.{1,2}|LICENSE|Global|\.gitignore)\z/,
+ "gitlab-ci-yml" => /(\.{1,2}|LICENSE|Pages|\.gitignore)\z/
+ }.freeze
+
+ def vendor_directory
+ Rails.root.join('vendor')
+ end
+
+ def gitignore_directory
+ File.join(vendor_directory, 'gitignore')
+ end
+
+ def gitlab_ci_directory
+ File.join(vendor_directory, 'gitlab-ci')
+ end
+end