summaryrefslogtreecommitdiff
path: root/lib/gitlab_update.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-14 14:02:18 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-14 14:02:18 +0200
commit12331a552b5921d6d212db774360a8f154fbffb0 (patch)
treedbcd2ec80f1ec70a5e92ba97bdcf5ae743da489c /lib/gitlab_update.rb
parentba68af63031a396df644807e1a428b5364f457da (diff)
downloadgitlab-shell-12331a552b5921d6d212db774360a8f154fbffb0.tar.gz
Use update hook to add post event to redis. Use GL_ID instead of GL_USER
Diffstat (limited to 'lib/gitlab_update.rb')
-rw-r--r--lib/gitlab_update.rb46
1 files changed, 30 insertions, 16 deletions
diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb
index 7bbb288..d6d135b 100644
--- a/lib/gitlab_update.rb
+++ b/lib/gitlab_update.rb
@@ -3,33 +3,38 @@ require_relative 'gitlab_net'
class GitlabUpdate
def initialize(repo_path, key_id, refname)
+ @repo_path = repo_path.strip
@repo_name = repo_path
@repo_name.gsub!(GitlabConfig.new.repos_path.to_s, "")
@repo_name.gsub!(/.git$/, "")
@repo_name.gsub!(/^\//, "")
@key_id = key_id
- @refname = /refs\/heads\/([\w\.-]+)/.match(refname).to_a.last
+ @refname = refname
+ @branch_name = /refs\/heads\/([\w\.-]+)/.match(refname).to_a.last
+
+ @oldrev = ARGV[1]
+ @newrev = ARGV[2]
end
def exec
- # Skip update hook for local push when key_id is nil
- # It required for gitlab instance to make local pushes
- # without validation of access
- exit 0 if @key_id.nil?
-
- # Also skip update hook for non-gitlab keys
- # and reset GL_USER env
- unless @key_id =~ /\Akey\-\d+\Z/
- ENV['GL_USER'] = nil
- exit 0
- end
+ # reset GL_USER env since we already
+ # get value from it
+ ENV['GL_ID'] = nil
- if api.allowed?('git-receive-pack', @repo_name, @key_id, @refname)
- exit 0
+ # If its push over ssh
+ # we need to check user persmission per branch first
+ if ssh?
+ if api.allowed?('git-receive-pack', @repo_name, @key_id, @branch_name)
+ update_redis
+ exit 0
+ else
+ puts "GitLab: You are not allowed to access #{@branch_name}! "
+ exit 1
+ end
else
- puts "GitLab: You are not allowed to access #{@refname}! "
- exit 1
+ update_redis
+ exit 0
end
end
@@ -38,4 +43,13 @@ class GitlabUpdate
def api
GitlabNet.new
end
+
+ def ssh?
+ @key_id =~ /\Akey\-\d+\Z/
+ end
+
+ def update_redis
+ command = "env -i redis-cli rpush 'resque:gitlab:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1"
+ system(command)
+ end
end