Skip to content

Commit d1bb9c5

Browse files
committed
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
2 parents 926bef4 + b0fc24c commit d1bb9c5

File tree

4 files changed

+90
-19
lines changed

4 files changed

+90
-19
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ source "http://rubygems.org"
22

33
group :development, :test do
44
gem 'coveralls', require: false
5-
gem 'rspec'
5+
gem 'rspec', '~> 2.14.0'
66
gem 'webmock'
77
gem 'guard'
88
gem 'guard-rspec'

Gemfile.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GEM
1313
term-ansicolor
1414
thor
1515
crack (0.3.1)
16-
diff-lcs (1.1.3)
16+
diff-lcs (1.2.5)
1717
docile (1.1.5)
1818
guard (1.5.4)
1919
listen (>= 0.4.2)
@@ -40,14 +40,14 @@ GEM
4040
rest-client (1.7.2)
4141
mime-types (>= 1.16, < 3.0)
4242
netrc (~> 0.7)
43-
rspec (2.12.0)
44-
rspec-core (~> 2.12.0)
45-
rspec-expectations (~> 2.12.0)
46-
rspec-mocks (~> 2.12.0)
47-
rspec-core (2.12.2)
48-
rspec-expectations (2.12.1)
49-
diff-lcs (~> 1.1.3)
50-
rspec-mocks (2.12.2)
43+
rspec (2.14.1)
44+
rspec-core (~> 2.14.0)
45+
rspec-expectations (~> 2.14.0)
46+
rspec-mocks (~> 2.14.0)
47+
rspec-core (2.14.8)
48+
rspec-expectations (2.14.5)
49+
diff-lcs (>= 1.1.3, < 2.0)
50+
rspec-mocks (2.14.6)
5151
rubocop (0.28.0)
5252
astrolabe (~> 1.3)
5353
parser (>= 2.2.0.pre.7, < 3.0)
@@ -77,7 +77,7 @@ DEPENDENCIES
7777
coveralls
7878
guard
7979
guard-rspec
80-
rspec
80+
rspec (~> 2.14.0)
8181
rubocop (= 0.28.0)
8282
vcr
8383
webmock

lib/gitlab_post_receive.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def exec
1616
# get value from it
1717
ENV['GL_ID'] = nil
1818

19-
update_redis
19+
result = update_redis
2020

2121
begin
2222
broadcast_message = GitlabNet.new.broadcast_message
@@ -28,6 +28,8 @@ def exec
2828
rescue GitlabNet::ApiUnreachableError
2929
nil
3030
end
31+
32+
result
3133
end
3234

3335
protected

spec/gitlab_post_receive_spec.rb

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,87 @@
44
describe GitlabPostReceive do
55
let(:repository_path) { "/home/git/repositories" }
66
let(:repo_name) { 'dzaporozhets/gitlab-ci' }
7+
let(:actor) { 'key-123' }
8+
let(:changes) { 'wow' }
79
let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
8-
let(:gitlab_post_receive) { GitlabPostReceive.new(repo_path, 'key-123', 'wow') }
10+
let(:gitlab_post_receive) { GitlabPostReceive.new(repo_path, actor, changes) }
11+
let(:message) { "test " * 10 + "message " * 10 }
912

1013
before do
1114
GitlabConfig.any_instance.stub(repos_path: repository_path)
12-
Kernel.stub(system: true)
13-
GitlabNet.any_instance.stub(broadcast_message: { "message" => "test " * 10 + "message " * 10 })
15+
GitlabNet.any_instance.stub(broadcast_message: { "message" => message })
1416
end
1517

16-
describe :initialize do
17-
it { gitlab_post_receive.repo_path.should == repo_path }
18-
it { gitlab_post_receive.changes.should == 'wow' }
19-
it { gitlab_post_receive.exec }
18+
describe "#exec" do
19+
20+
before do
21+
GitlabConfig.any_instance.stub(redis_command: %w(env -i redis-cli))
22+
allow(gitlab_post_receive).to receive(:system).and_return(true)
23+
end
24+
25+
it "resets the GL_ID environment variable" do
26+
ENV["GL_ID"] = actor
27+
28+
gitlab_post_receive.exec
29+
30+
expect(ENV["GL_ID"]).to be_nil
31+
end
32+
33+
it "prints the broadcast message" do
34+
expect(gitlab_post_receive).to receive(:puts).ordered
35+
expect(gitlab_post_receive).to receive(:puts).with(
36+
"========================================================================"
37+
).ordered
38+
expect(gitlab_post_receive).to receive(:puts).ordered
39+
40+
expect(gitlab_post_receive).to receive(:puts).with(
41+
" test test test test test test test test test test message message"
42+
).ordered
43+
expect(gitlab_post_receive).to receive(:puts).with(
44+
" message message message message message message message message"
45+
).ordered
46+
47+
expect(gitlab_post_receive).to receive(:puts).ordered
48+
expect(gitlab_post_receive).to receive(:puts).with(
49+
"========================================================================"
50+
).ordered
51+
52+
gitlab_post_receive.exec
53+
end
54+
55+
it "pushes a Sidekiq job onto the queue" do
56+
expect(gitlab_post_receive).to receive(:system).with(
57+
*[
58+
*%w(env -i redis-cli rpush resque:gitlab:queue:post_receive),
59+
%Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}","#{changes}"]}/,
60+
{ err: "/dev/null", out: "/dev/null" }
61+
]
62+
).and_return(true)
63+
64+
gitlab_post_receive.exec
65+
end
66+
67+
context "when the redis command succeeds" do
68+
69+
before do
70+
allow(gitlab_post_receive).to receive(:system).and_return(true)
71+
end
72+
73+
it "returns true" do
74+
expect(gitlab_post_receive.exec).to eq(true)
75+
end
76+
end
77+
78+
context "when the redis command fails" do
79+
80+
before do
81+
allow(gitlab_post_receive).to receive(:system).and_return(false)
82+
allow($?).to receive(:exitstatus).and_return(nil)
83+
end
84+
85+
it "returns false" do
86+
expect(gitlab_post_receive.exec).to eq(false)
87+
end
88+
end
2089
end
2190
end

0 commit comments

Comments
 (0)