summaryrefslogtreecommitdiff
path: root/lib/gitlab_update.rb
diff options
context:
space:
mode:
authorMichael <michael@fallo.ws>2013-03-10 06:05:23 -0700
committerMichael <michael@fallo.ws>2013-03-10 06:05:23 -0700
commit4bbda0b2590fc5081638c113c7cf74b60c8680b2 (patch)
tree69023666966e396663ee13c52e3b4b2edbf535a4 /lib/gitlab_update.rb
parent381f4cdb0e5c625dc3def0bc66085dcb0ccd4efc (diff)
parentfc8bd8f760fac40287681894dfd9a45e8c4d0517 (diff)
downloadgitlab-shell-4bbda0b2590fc5081638c113c7cf74b60c8680b2.tar.gz
Merge pull request #1 from gitlabhq/master
Master Sync
Diffstat (limited to 'lib/gitlab_update.rb')
-rw-r--r--lib/gitlab_update.rb36
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb
index cf3953e..156e385 100644
--- a/lib/gitlab_update.rb
+++ b/lib/gitlab_update.rb
@@ -3,21 +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
- if api.allowed?('git-receive-pack', @repo_name, @key_id, @refname)
- exit 0
+ # reset GL_ID env since we already
+ # get value from it
+ ENV['GL_ID'] = nil
+
+ # 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
@@ -26,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