Merge pull request #191 from warpc/134-git-hook
[refs #134] Fixed git hook (hadr-coded desctionation and wrong rails env)
This commit is contained in:
commit
98059d6570
|
@ -213,7 +213,7 @@ class Project < ActiveRecord::Base
|
|||
|
||||
def write_hook
|
||||
hook_file = File.join(path, 'hooks', 'post-receive')
|
||||
FileUtils.cp(File.join(::Rails.root.to_s, 'lib', 'post-receive-hook'), hook_file)
|
||||
FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}"), hook_file)
|
||||
#File.chmod(0775, hook_file) # need?
|
||||
rescue Exception # FIXME
|
||||
end
|
||||
|
|
|
@ -9,7 +9,4 @@ owner=`basename \`dirname $pwd\``
|
|||
while read oldrev newrev ref
|
||||
do
|
||||
newrev_type=$(git cat-file -t $newrev 2> /dev/null)
|
||||
oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null)
|
||||
|
||||
/bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'"
|
||||
done
|
||||
oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null)
|
|
@ -1,13 +0,0 @@
|
|||
class WriteGitHookToProjects < ActiveRecord::Migration
|
||||
def self.up
|
||||
origin_hook = File.join(::Rails.root.to_s, 'lib', 'post-receive-hook')
|
||||
Project.all.each do |project|
|
||||
hook_file = File.join(project.path, 'hooks', 'post-receive')
|
||||
FileUtils.cp(origin_hook, hook_file)
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive')}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
namespace :hook do
|
||||
desc "Inserting hook to all repos"
|
||||
task :install => :environment do
|
||||
is_production = ENV['RAILS_ENV'] == 'production'
|
||||
say "Generate temporary file..."
|
||||
hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook")
|
||||
FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook)
|
||||
File.open(hook, 'a') do |f|
|
||||
s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && \
|
||||
bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\""
|
||||
s << " > /dev/null 2>&1" if is_production
|
||||
s << "\ndone\n"
|
||||
f.write(s)
|
||||
end
|
||||
|
||||
say "Install process.."
|
||||
count = 0
|
||||
Project.all.each do |project|
|
||||
hook_file = File.join(project.path, 'hooks', 'post-receive')
|
||||
FileUtils.cp(hook, hook_file)
|
||||
count = count + 1
|
||||
end
|
||||
say "Writing to #{count.to_s} repo(s)"
|
||||
say "Removing temporary file"
|
||||
FileUtils.rm_rf(hook)
|
||||
end
|
||||
|
||||
desc "remove git hook from all repos"
|
||||
task :remove => :environment do
|
||||
say "process.."
|
||||
count = 0
|
||||
Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive'); count = count + 1}
|
||||
say "Done! Removing from #{count.to_s} repo(s)"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue