summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-11-30 17:22:00 +0000
committerValery Sizov <valery@gitlab.com>2015-11-30 17:22:00 +0000
commit13c6096e42e5b20039f78b9415bea82e1f2507eb (patch)
treebed2f1dd8bdeedfd1c412ef458218097af6da083
parentceeb93fa77783a3fa9a60529195cd187af191bba (diff)
parentae18ba16327abd79cf6207b83209d4ef96d3e158 (diff)
downloadgitlab-ce-13c6096e42e5b20039f78b9415bea82e1f2507eb.tar.gz
Merge branch 'upload_hook' into 'master'
Fire update hook from GitLab https://gitlab.com/gitlab-org/gitlab-ce/issues/3069 See merge request !1882
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/repository.rb10
-rw-r--r--lib/gitlab/git/hook.rb17
3 files changed, 25 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 1e8fb670325..1ab1310c62e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@ v 8.3.0 (unreleased)
- Fix: Assignee selector is empty when 'Unassigned' is selected (Jose Corcuera)
- Fix 500 error when update group member permission
- Trim leading and trailing whitespace of milestone and issueable titles (Jose Corcuera)
+ - Fire update hook from GitLab
v 8.2.2
- Fix 404 in redirection after removing a project (Stan Hu)
diff --git a/app/models/repository.rb b/app/models/repository.rb
index c1836103463..d247b0f5012 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -571,9 +571,13 @@ class Repository
# Run GitLab pre-receive hook
pre_receive_hook = Gitlab::Git::Hook.new('pre-receive', path_to_repo)
- status = pre_receive_hook.trigger(gl_id, oldrev, newrev, ref)
+ pre_receive_hook_status = pre_receive_hook.trigger(gl_id, oldrev, newrev, ref)
- if status
+ # Run GitLab update hook
+ update_hook = Gitlab::Git::Hook.new('update', path_to_repo)
+ update_hook_status = update_hook.trigger(gl_id, oldrev, newrev, ref)
+
+ if pre_receive_hook_status && update_hook_status
if was_empty
# Create branch
rugged.references.create(ref, newrev)
@@ -596,7 +600,7 @@ class Repository
# Remove tmp ref and return error to user
rugged.references.delete(tmp_ref)
- raise PreReceiveError.new('Commit was rejected by pre-receive hook')
+ raise PreReceiveError.new('Commit was rejected by git hook')
end
end
diff --git a/lib/gitlab/git/hook.rb b/lib/gitlab/git/hook.rb
index dd393fe09d2..07b856ca64c 100644
--- a/lib/gitlab/git/hook.rb
+++ b/lib/gitlab/git/hook.rb
@@ -16,6 +16,17 @@ module Gitlab
def trigger(gl_id, oldrev, newrev, ref)
return true unless exists?
+ case name
+ when "pre-receive", "post-receive"
+ call_receive_hook(gl_id, oldrev, newrev, ref)
+ when "update"
+ call_update_hook(gl_id, oldrev, newrev, ref)
+ end
+ end
+
+ private
+
+ def call_receive_hook(gl_id, oldrev, newrev, ref)
changes = [oldrev, newrev, ref].join(" ")
# function will return true if succesful
@@ -54,6 +65,12 @@ module Gitlab
exit_status
end
+
+ def call_update_hook(gl_id, oldrev, newrev, ref)
+ Dir.chdir(repo_path) do
+ system({ 'GL_ID' => gl_id }, path, ref, oldrev, newrev)
+ end
+ end
end
end
end