Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorZ.J. van de Weg <zegerjan@gitlab.com>2016-06-02 19:20:08 +0300
committerAlfredo Sumaran <alfredo@gitlab.com>2016-06-20 22:48:28 +0300
commit620d014aefd23030ed6ae043e223ccc5dc52fc8a (patch)
tree9324f2cbb23bdcc4f02d9b29b349894e4b43ac8c /lib/tasks
parent567f6a7b4271d97afd6dea1545210b9aba858421 (diff)
Implement backend gitlab ci dropdown
This commit builds on the groundwork in ee008e300b1ec0abcc90e6a30816ec0754cea0dd, which refactored the backend so the same code could be used for new dropdowns. In this commit its used for templates for the `.gitlab-ci.yml` files.
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gitlab/update_templates.rake55
1 files changed, 23 insertions, 32 deletions
diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake
index 36ffad8aae9..90b1a64ed5a 100644
--- a/lib/tasks/gitlab/update_templates.rake
+++ b/lib/tasks/gitlab/update_templates.rake
@@ -1,35 +1,34 @@
namespace :gitlab do
desc "GitLab | Update templates"
task :update_templates do
- update("gitignore")
- update("gitlab-ci-yml")
+ TEMPLATE_DATA.each { |template| update(template) }
end
- def update(directory)
- unless clone_repository(directory)
- puts "Cloning the #{directory} templates failed".red
+ def update(template)
+ sub_dir = template.repo_url.match(/([a-z-]+)\.git\z/)[1]
+ dir = File.join(vendor_directory, sub_dir)
+
+ unless clone_repository(template.repo_url, dir)
+ puts "Cloning the #{sub_dir} templates failed".red
return
end
- remove_unneeded_files(directory)
+ remove_unneeded_files(dir, template.cleanup_regex)
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
+ def clone_repository(url, directory)
+ FileUtils.rm_rf(directory) if Dir.exist?(directory)
- system("git clone --depth=1 --branch=master #{TEMPLATE_DATA[directory]}")
+ system("git clone #{url} --depth=1 --branch=master #{directory}")
end
# Retain only certain files:
# - The LICENSE, because we have to
- # - The sub dir global
- # - The gitignores themself
+ # - The sub dirs so we can organise the file by category
+ # - The templates themself
# - Dir.entires returns also the entries '.' and '..'
- def remove_unneeded_files(directory)
- regex = CLEANUP_REGEX[directory]
+ def remove_unneeded_files(directory, regex)
Dir.foreach(directory) do |file|
FileUtils.rm_rf(File.join(directory, file)) unless file =~ regex
end
@@ -37,25 +36,17 @@ namespace :gitlab do
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
+ Template = Struct.new(:repo_url, :cleanup_regex)
+ TEMPLATE_DATA = [Template.new(
+ "https://github.com/github/gitignore.git",
+ /(\.{1,2}|LICENSE|Global|\.gitignore)\z/
+ ),
+ Template.new(
+ "https://gitlab.com/gitlab-org/gitlab-ci-yml.git",
+ /(\.{1,2}|LICENSE|Pages|\.gitignore)\z/
+ )]
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