summaryrefslogtreecommitdiff
path: root/lib/gitlab_update.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab_update.rb')
-rw-r--r--lib/gitlab_update.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb
new file mode 100644
index 0000000..cf3953e
--- /dev/null
+++ b/lib/gitlab_update.rb
@@ -0,0 +1,29 @@
+require_relative 'gitlab_init'
+require_relative 'gitlab_net'
+
+class GitlabUpdate
+ def initialize(repo_path, key_id, refname)
+ @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
+ end
+
+ def exec
+ if api.allowed?('git-receive-pack', @repo_name, @key_id, @refname)
+ exit 0
+ else
+ puts "GitLab: You are not allowed to access #{@refname}! "
+ exit 1
+ end
+ end
+
+ protected
+
+ def api
+ GitlabNet.new
+ end
+end