Commit fad9498c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'add_gl_id' into 'master'

Re-exposing GL_ID to custom hooks

closes https://gitlab.com/gitlab-org/gitlab-ee/issues/995
closes https://gitlab.com/gitlab-org/gitlab-shell/issues/53

See merge request !95
parents c04e2ae0 c0b47341
v3.6.3
- Re-exposing GL_ID to custom hooks
v3.6.2
- Enable GIT_TRACE/GIT_TRACE_PACKET/GIT_TRACE_PERFORMANCE by providing the git_trace_log_file config key
......
......@@ -11,7 +11,7 @@ require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_post_receive'
if GitlabPostReceive.new(repo_path, key_id, refs).exec &&
GitlabCustomHook.new.post_receive(refs, repo_path)
GitlabCustomHook.new(key_id).post_receive(refs, repo_path)
exit 0
else
exit 1
......
......@@ -17,7 +17,7 @@ require_relative '../lib/gitlab_access'
# other hand, we run GitlabPostReceive first because the push is already done
# and we don't want to skip it if the custom hook fails.
if GitlabAccess.new(repo_path, key_id, refs, protocol).exec &&
GitlabCustomHook.new.pre_receive(refs, repo_path) &&
GitlabCustomHook.new(key_id).pre_receive(refs, repo_path) &&
GitlabReferenceCounter.new(repo_path).increase
exit 0
else
......
......@@ -3,14 +3,15 @@
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
ref_name = ARGV[0]
ref_name = ARGV[0]
old_value = ARGV[1]
new_value = ARGV[2]
repo_path = Dir.pwd
key_id = ENV.delete('GL_ID')
require_relative '../lib/gitlab_custom_hook'
if GitlabCustomHook.new.update(ref_name, old_value, new_value, repo_path)
if GitlabCustomHook.new(key_id).update(ref_name, old_value, new_value, repo_path)
exit 0
else
exit 1
......
require 'open3'
class GitlabCustomHook
attr_reader :vars
def initialize(key_id)
@vars = { 'GL_ID' => key_id }
end
def pre_receive(changes, repo_path)
hook = hook_file('pre-receive', repo_path)
return true if hook.nil?
......@@ -11,7 +17,7 @@ class GitlabCustomHook
def post_receive(changes, repo_path)
hook = hook_file('post-receive', repo_path)
return true if hook.nil?
call_receive_hook(hook, changes)
end
......@@ -19,7 +25,7 @@ class GitlabCustomHook
hook = hook_file('update', repo_path)
return true if hook.nil?
system(hook, ref_name, old_value, new_value)
system(vars, hook, ref_name, old_value, new_value)
end
private
......@@ -28,7 +34,7 @@ class GitlabCustomHook
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge
# both its stdout and stderr into our own stdout.
stdin_reader, stdin_writer = IO.pipe
hook_pid = spawn(hook, in: stdin_reader, err: :out)
hook_pid = spawn(vars, hook, in: stdin_reader, err: :out)
stdin_reader.close
# Submit changes to the hook via its stdin.
......
# coding: utf-8
require 'spec_helper'
require 'pry'
require 'gitlab_custom_hook'
describe GitlabCustomHook do
let(:gitlab_custom_hook) { GitlabCustomHook.new('key_1') }
let(:hook_path) { File.join(ROOT_PATH, 'spec/support/gl_id_test_hook') }
context 'pre_receive hook' do
it 'passes GL_ID variable to hook' do
allow(gitlab_custom_hook).to receive(:hook_file).and_return(hook_path)
expect(gitlab_custom_hook.pre_receive('changes', 'repo_path')).to be_true
end
end
context 'post_receive hook' do
it 'passes GL_ID variable to hook' do
allow(gitlab_custom_hook).to receive(:hook_file).and_return(hook_path)
expect(gitlab_custom_hook.post_receive('changes', 'repo_path')).to be_true
end
end
context 'update hook' do
it 'passes GL_ID variable to hook' do
allow(gitlab_custom_hook).to receive(:hook_file).and_return(hook_path)
expect(gitlab_custom_hook.update('master', '', '', 'repo_path')).to be_true
end
end
end
#!/bin/sh
printenv GL_ID | grep -q '^key_1$'
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