2012-02-15 11:12:49 +00:00
|
|
|
namespace :hook do
|
|
|
|
desc "Inserting hook to all repos"
|
2014-01-21 04:51:49 +00:00
|
|
|
task install: :environment do
|
2013-03-07 08:06:34 +00:00
|
|
|
hook = "/home/#{APP_CONFIG['shell_user']}/gitlab-shell/hooks/post-receive"
|
2012-02-15 13:06:25 +00:00
|
|
|
say "Install process.."
|
2014-03-18 08:15:38 +00:00
|
|
|
count, projects = 0, Project.all
|
2014-01-21 04:51:49 +00:00
|
|
|
projects = projects.where(id: ENV['PROJECT_ID']) if ENV['PROJECT_ID']
|
2013-03-07 08:06:34 +00:00
|
|
|
projects.each do |project|
|
|
|
|
next unless Dir.exist? project.path
|
2012-02-15 11:12:49 +00:00
|
|
|
hook_file = File.join(project.path, 'hooks', 'post-receive')
|
2013-03-07 08:06:34 +00:00
|
|
|
FileUtils.rm_rf hook_file
|
2012-04-02 20:30:14 +01:00
|
|
|
begin
|
2013-03-07 08:06:34 +00:00
|
|
|
FileUtils.ln_sf(hook, hook_file)
|
2012-04-02 20:30:14 +01:00
|
|
|
count = count + 1
|
|
|
|
rescue Exception => e
|
|
|
|
say "----\nCatching exception with project #{project.id}"
|
|
|
|
say e.message
|
|
|
|
say '----'
|
|
|
|
end
|
2012-02-15 11:12:49 +00:00
|
|
|
end
|
2012-02-15 13:06:25 +00:00
|
|
|
say "Writing to #{count.to_s} repo(s)"
|
2012-06-16 19:27:46 +01:00
|
|
|
end
|
|
|
|
|
2012-02-15 11:23:49 +00:00
|
|
|
desc "remove git hook from all repos"
|
2014-01-21 04:51:49 +00:00
|
|
|
task remove: :environment do
|
2012-02-15 11:12:49 +00:00
|
|
|
say "process.."
|
2014-03-18 08:15:38 +00:00
|
|
|
count, projects = 0, Project.all
|
2014-01-21 04:51:49 +00:00
|
|
|
projects = projects.where(id: ENV['PROJECT_ID']) if ENV['PROJECT_ID']
|
2013-03-07 08:06:34 +00:00
|
|
|
projects.each do |project|
|
2012-02-17 09:22:55 +00:00
|
|
|
FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive')
|
|
|
|
count = count + 1
|
|
|
|
end
|
2012-02-15 11:12:49 +00:00
|
|
|
say "Done! Removing from #{count.to_s} repo(s)"
|
|
|
|
end
|
|
|
|
end
|