Commit 7eb45672 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Remove update hook logic

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent fc168367
#!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
# You can add your own hooks to this file, but be careful when updating gitlab-shell!
refname = ARGV[0]
key_id = ENV['GL_ID']
repo_path = Dir.pwd
require_relative '../lib/gitlab_update'
GitlabUpdate.new(repo_path, key_id, refname).exec
require_relative 'gitlab_init'
require_relative 'gitlab_net'
require_relative 'names_helper'
require 'json'
class GitlabUpdate
include NamesHelper
attr_reader :config, :repo_path, :repo_name,
:ref, :ref_name, :oldrev, :newrev
def initialize(repo_path, actor, ref)
@config = GitlabConfig.new
@repo_path, @actor, @ref = repo_path.strip, actor, ref
@repo_name = extract_repo_name(@repo_path.dup, config.repos_path.to_s)
@ref_name = extract_ref_name(ref)
@oldrev = ARGV[1]
@newrev = ARGV[2]
end
def forced_push?
if @oldrev !~ /00000000/ && @newrev !~ /00000000/
missed_refs = IO.popen(%W(git rev-list #{@oldrev} ^#{@newrev})).read
missed_refs.split("\n").size > 0
else
false
end
end
def exec
# reset GL_ID env since we already
# get value from it
ENV['GL_ID'] = nil
if api.allowed?('git-receive-pack', @repo_name, @actor, @ref_name, @oldrev, @newrev, forced_push?)
update_redis
exit 0
else
puts "GitLab: You are not allowed to access #{@ref_name}!"
exit 1
end
end
protected
def api
GitlabNet.new
end
def update_redis
queue = "#{config.redis_namespace}:queue:post_receive"
msg = JSON.dump({'class' => 'PostReceive', 'args' => [@repo_path, @oldrev, @newrev, @ref, @actor]})
unless system(*config.redis_command, 'rpush', queue, msg, err: '/dev/null', out: '/dev/null')
puts "GitLab: An unexpected error occurred (redis-cli returned #{$?.exitstatus})."
exit 1
end
end
end
...@@ -295,7 +295,8 @@ describe GitlabProjects do ...@@ -295,7 +295,8 @@ describe GitlabProjects do
FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace')) FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace'))
gl_projects_fork.exec.should be_true gl_projects_fork.exec.should be_true
File.exists?(dest_repo).should be_true File.exists?(dest_repo).should be_true
File.exists?(File.join(dest_repo, '/hooks/update')).should be_true File.exists?(File.join(dest_repo, '/hooks/pre-receive')).should be_true
File.exists?(File.join(dest_repo, '/hooks/post-receive')).should be_true
end end
it "should not fork if a project of the same name already exists" do it "should not fork if a project of the same name already exists" do
......
require 'spec_helper'
require 'gitlab_update'
describe GitlabUpdate do
let(:repository_path) { "/home/git/repositories" }
let(:repo_name) { 'dzaporozhets/gitlab-ci' }
let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
let(:ref) { 'refs/heads/awesome-feature' }
let(:gitlab_update) { GitlabUpdate.new(repo_path, 'key-123', ref) }
before do
ARGV[1] = 'd1e3ca3b25'
ARGV[2] = 'c2b3653b25'
GitlabConfig.any_instance.stub(repos_path: repository_path)
end
describe :initialize do
it { gitlab_update.repo_name.should == repo_name }
it { gitlab_update.repo_path.should == repo_path }
it { gitlab_update.ref.should == ref }
it { gitlab_update.ref_name.should == 'awesome-feature' }
it { gitlab_update.oldrev.should == 'd1e3ca3b25' }
it { gitlab_update.newrev.should == 'c2b3653b25' }
end
end
require 'spec_helper' require 'spec_helper'
require 'gitlab_update' require 'names_helper'
describe NamesHelper do describe NamesHelper do
include NamesHelper include NamesHelper
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment