summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2015-02-24 05:26:14 +0000
committerMarin Jankovski <marin@gitlab.com>2015-02-24 05:26:14 +0000
commitd1bb9c5cebc9f89d715569582ce9284d72cd7849 (patch)
tree56c3c484b53c5e1b2ee1bae72106c6f92594011a
parent926bef44f0c14a2ef22406c3fe885cd0be2903ae (diff)
parentb0fc24c9bfbcf8a7fdf3723b74810f5615bb4337 (diff)
downloadgitlab-shell-d1bb9c5cebc9f89d715569582ce9284d72cd7849.tar.gz
Merge branch 'fix-post-receive' into 'master'
Return true from GitlabPostReceive to ensure custom hooks run. Fixes https://gitlab.com/gitlab-org/omnibus-gitlab/issues/438. See merge request !62
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock20
-rw-r--r--lib/gitlab_post_receive.rb4
-rw-r--r--spec/gitlab_post_receive_spec.rb83
4 files changed, 90 insertions, 19 deletions
diff --git a/Gemfile b/Gemfile
index fc6af33..7c5ce9d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,7 +2,7 @@ source "http://rubygems.org"
group :development, :test do
gem 'coveralls', require: false
- gem 'rspec'
+ gem 'rspec', '~> 2.14.0'
gem 'webmock'
gem 'guard'
gem 'guard-rspec'
diff --git a/Gemfile.lock b/Gemfile.lock
index 9684ce8..9bf7d9f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -13,7 +13,7 @@ GEM
term-ansicolor
thor
crack (0.3.1)
- diff-lcs (1.1.3)
+ diff-lcs (1.2.5)
docile (1.1.5)
guard (1.5.4)
listen (>= 0.4.2)
@@ -40,14 +40,14 @@ GEM
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
- rspec (2.12.0)
- rspec-core (~> 2.12.0)
- rspec-expectations (~> 2.12.0)
- rspec-mocks (~> 2.12.0)
- rspec-core (2.12.2)
- rspec-expectations (2.12.1)
- diff-lcs (~> 1.1.3)
- rspec-mocks (2.12.2)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.8)
+ rspec-expectations (2.14.5)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.6)
rubocop (0.28.0)
astrolabe (~> 1.3)
parser (>= 2.2.0.pre.7, < 3.0)
@@ -77,7 +77,7 @@ DEPENDENCIES
coveralls
guard
guard-rspec
- rspec
+ rspec (~> 2.14.0)
rubocop (= 0.28.0)
vcr
webmock
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb
index 154e045..f7ff153 100644
--- a/lib/gitlab_post_receive.rb
+++ b/lib/gitlab_post_receive.rb
@@ -16,7 +16,7 @@ class GitlabPostReceive
# get value from it
ENV['GL_ID'] = nil
- update_redis
+ result = update_redis
begin
broadcast_message = GitlabNet.new.broadcast_message
@@ -28,6 +28,8 @@ class GitlabPostReceive
rescue GitlabNet::ApiUnreachableError
nil
end
+
+ result
end
protected
diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb
index dc84e4a..fdb9e27 100644
--- a/spec/gitlab_post_receive_spec.rb
+++ b/spec/gitlab_post_receive_spec.rb
@@ -4,18 +4,87 @@ require 'gitlab_post_receive'
describe GitlabPostReceive do
let(:repository_path) { "/home/git/repositories" }
let(:repo_name) { 'dzaporozhets/gitlab-ci' }
+ let(:actor) { 'key-123' }
+ let(:changes) { 'wow' }
let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
- let(:gitlab_post_receive) { GitlabPostReceive.new(repo_path, 'key-123', 'wow') }
+ let(:gitlab_post_receive) { GitlabPostReceive.new(repo_path, actor, changes) }
+ let(:message) { "test " * 10 + "message " * 10 }
before do
GitlabConfig.any_instance.stub(repos_path: repository_path)
- Kernel.stub(system: true)
- GitlabNet.any_instance.stub(broadcast_message: { "message" => "test " * 10 + "message " * 10 })
+ GitlabNet.any_instance.stub(broadcast_message: { "message" => message })
end
- describe :initialize do
- it { gitlab_post_receive.repo_path.should == repo_path }
- it { gitlab_post_receive.changes.should == 'wow' }
- it { gitlab_post_receive.exec }
+ describe "#exec" do
+
+ before do
+ GitlabConfig.any_instance.stub(redis_command: %w(env -i redis-cli))
+ allow(gitlab_post_receive).to receive(:system).and_return(true)
+ end
+
+ it "resets the GL_ID environment variable" do
+ ENV["GL_ID"] = actor
+
+ gitlab_post_receive.exec
+
+ expect(ENV["GL_ID"]).to be_nil
+ end
+
+ it "prints the broadcast message" do
+ expect(gitlab_post_receive).to receive(:puts).ordered
+ expect(gitlab_post_receive).to receive(:puts).with(
+ "========================================================================"
+ ).ordered
+ expect(gitlab_post_receive).to receive(:puts).ordered
+
+ expect(gitlab_post_receive).to receive(:puts).with(
+ " test test test test test test test test test test message message"
+ ).ordered
+ expect(gitlab_post_receive).to receive(:puts).with(
+ " message message message message message message message message"
+ ).ordered
+
+ expect(gitlab_post_receive).to receive(:puts).ordered
+ expect(gitlab_post_receive).to receive(:puts).with(
+ "========================================================================"
+ ).ordered
+
+ gitlab_post_receive.exec
+ end
+
+ it "pushes a Sidekiq job onto the queue" do
+ expect(gitlab_post_receive).to receive(:system).with(
+ *[
+ *%w(env -i redis-cli rpush resque:gitlab:queue:post_receive),
+ %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}","#{changes}"]}/,
+ { err: "/dev/null", out: "/dev/null" }
+ ]
+ ).and_return(true)
+
+ gitlab_post_receive.exec
+ end
+
+ context "when the redis command succeeds" do
+
+ before do
+ allow(gitlab_post_receive).to receive(:system).and_return(true)
+ end
+
+ it "returns true" do
+ expect(gitlab_post_receive.exec).to eq(true)
+ end
+ end
+
+ context "when the redis command fails" do
+
+ before do
+ allow(gitlab_post_receive).to receive(:system).and_return(false)
+ allow($?).to receive(:exitstatus).and_return(nil)
+ end
+
+ it "returns false" do
+ expect(gitlab_post_receive.exec).to eq(false)
+ end
+ end
end
end