[refs #134] fixed git hook

This commit is contained in:
Alexander Machehin 2012-02-15 17:12:49 +06:00 committed by Vladimir Sharshov
parent aedfc0df8c
commit 41861185c0
5 changed files with 54 additions and 14 deletions

View File

@ -219,7 +219,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

15
bin/post-receive-hook_dev Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly.
pwd=`pwd`
reponame=`basename $pwd .git`
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

View File

@ -0,0 +1,15 @@
#!/bin/bash
# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly.
pwd=`pwd`
reponame=`basename $pwd .git`
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 && RAILS_ENV=production bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" > /dev/null 2>&1
done

View File

@ -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

23
lib/tasks/hook.rake Normal file
View File

@ -0,0 +1,23 @@
namespace :hook do
desc "Inserting hook to all repos"
task :install => :environment do
origin_hook = File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}")
say "process.. #{origin_hook}"
count = 0
Project.all.each do |project|
hook_file = File.join(project.path, 'hooks', 'post-receive')
FileUtils.cp(origin_hook, hook_file)
count = count + 1
end
say "Done! Writing to #{count.to_s} repo(s)"
end
desc "remove with git hook"
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