summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-02-05 15:23:28 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-02-07 18:05:52 -0300
commitb98d59acdf6453708ec53e38146238cab9f9754c (patch)
tree741896b1285ea9f595de8642704a69a81a3c7b0f
parentf61bdfe39c6b0618144f369d5cf4df1099be9948 (diff)
downloadgitlab-shell-b98d59acdf6453708ec53e38146238cab9f9754c.tar.gz
Add gitaly notification on post-receive hook
-rw-r--r--lib/gitlab_net.rb8
-rw-r--r--lib/gitlab_post_receive.rb2
-rw-r--r--spec/gitlab_post_receive_spec.rb10
3 files changed, 20 insertions, 0 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index e06557c..e8377cc 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -93,6 +93,14 @@ class GitlabNet
{}
end
+ def notify_post_receive(repo_path)
+ resp = post("#{host}/notify_post_receive", repo_path: repo_path)
+
+ resp.code == '200'
+ rescue
+ false
+ end
+
def redis_client
redis_config = config.redis
database = redis_config['database'] || 0
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb
index 7e3b310..8383135 100644
--- a/lib/gitlab_post_receive.rb
+++ b/lib/gitlab_post_receive.rb
@@ -35,6 +35,8 @@ class GitlabPostReceive
api.merge_request_urls(@repo_path, @changes)
end
print_merge_request_links(merge_request_urls)
+
+ api.notify_post_receive(repo_path)
rescue GitlabNet::ApiUnreachableError
nil
end
diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb
index 711545f..c63c267 100644
--- a/spec/gitlab_post_receive_spec.rb
+++ b/spec/gitlab_post_receive_spec.rb
@@ -19,6 +19,7 @@ describe GitlabPostReceive do
GitlabConfig.any_instance.stub(repos_path: repository_path)
GitlabNet.any_instance.stub(broadcast_message: { })
GitlabNet.any_instance.stub(:merge_request_urls).with(repo_path, wrongly_encoded_changes) { [] }
+ GitlabNet.any_instance.stub(notify_post_receive: true)
expect(Time).to receive(:now).and_return(enqueued_at)
end
@@ -172,6 +173,15 @@ describe GitlabPostReceive do
end
end
+ context 'post_receive notification' do
+ it 'calls the api to notify the execution of the hook' do
+ expect_any_instance_of(GitlabNet).to receive(:notify_post_receive).
+ with(repo_path)
+
+ gitlab_post_receive.exec
+ end
+ end
+
context "when the redis command succeeds" do
before do