First attempt at a post-receive hook that posts directly to Resque
This commit is contained in:
parent
1c9b9b7a3b
commit
bc0155fbaa
5 changed files with 30 additions and 14 deletions
|
@ -31,6 +31,17 @@ class Repository
|
||||||
project.id
|
project.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# repo.update_hook('post-receive', File.read('some-hook'))
|
||||||
|
def update_hook(name, content)
|
||||||
|
hook_file = File.join(project.path_to_repo, 'hooks', name)
|
||||||
|
|
||||||
|
File.open(hook_file, 'w') do |f|
|
||||||
|
f.write(content)
|
||||||
|
end
|
||||||
|
|
||||||
|
File.chmod(0775, hook_file)
|
||||||
|
end
|
||||||
|
|
||||||
def repo
|
def repo
|
||||||
@repo ||= Grit::Repo.new(project.path_to_repo)
|
@repo ||= Grit::Repo.new(project.path_to_repo)
|
||||||
end
|
end
|
||||||
|
|
5
app/workers/post_receive.rb
Normal file
5
app/workers/post_receive.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class PostReceive
|
||||||
|
def self.perform(reponame, oldrev, newrev, ref)
|
||||||
|
puts "[#{reponame}] #{oldrev} => #{newrev} (#{ref})"
|
||||||
|
end
|
||||||
|
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -13,18 +13,6 @@
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20111207211728) do
|
ActiveRecord::Schema.define(:version => 20111207211728) do
|
||||||
|
|
||||||
create_table "features", :force => true do |t|
|
|
||||||
t.string "name"
|
|
||||||
t.string "branch_name"
|
|
||||||
t.integer "assignee_id"
|
|
||||||
t.integer "author_id"
|
|
||||||
t.integer "project_id"
|
|
||||||
t.datetime "created_at"
|
|
||||||
t.datetime "updated_at"
|
|
||||||
t.string "version"
|
|
||||||
t.integer "status", :default => 0, :null => false
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "issues", :force => true do |t|
|
create_table "issues", :force => true do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.integer "assignee_id"
|
t.integer "assignee_id"
|
||||||
|
|
12
lib/post-receive-hook
Executable file
12
lib/post-receive-hook
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file was placed here by Gitlab. It makes sure that your pushed commits
|
||||||
|
# will be processed properly.
|
||||||
|
|
||||||
|
while read oldrev newrev ref
|
||||||
|
do
|
||||||
|
# For every branch or tag that was pushed, create a Resque job in redis.
|
||||||
|
pwd=`pwd`
|
||||||
|
reponame=`basename "$pwd" | cut -d. -f1`
|
||||||
|
env -i redis-cli rpush "resque:queue:post-receive" "{\"class\":\"PostReceive\",\"args\":[\"$reponame\",\"$oldrev\",\"$newrev\",\"$ref\"]}" > /dev/null 2>&1
|
||||||
|
done
|
Loading…
Reference in a new issue