Commit 8ab4228b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve broadcast message logic

Expect broadcast message API endpoint to return 200 with empty JSON if
no broadcast messages available
parent b0979371
v2.5.1
- Expect broadcast message to return empty JSON if no message now
v2.5.0 v2.5.0
- Support git-annex tool (disabled by default) - Support git-annex tool (disabled by default)
- Add rubocop (Ruby static code analyzer) for development - Add rubocop (Ruby static code analyzer) for development
......
...@@ -45,11 +45,7 @@ class GitlabNet ...@@ -45,11 +45,7 @@ class GitlabNet
def broadcast_message def broadcast_message
resp = get("#{host}/broadcast_message") resp = get("#{host}/broadcast_message")
if resp.code == '200' JSON.parse(resp.body) rescue {}
JSON.parse(resp.body) rescue nil
else
nil
end
end end
def check def check
...@@ -95,7 +91,7 @@ class GitlabNet ...@@ -95,7 +91,7 @@ class GitlabNet
$logger.debug "Performing #{method.to_s.upcase} #{url}" $logger.debug "Performing #{method.to_s.upcase} #{url}"
uri = URI.parse(url) uri = URI.parse(url)
http = http_client_for(uri) http = http_client_for(uri)
request = http_request_for(method, uri, params) request = http_request_for(method, uri, params)
...@@ -103,7 +99,7 @@ class GitlabNet ...@@ -103,7 +99,7 @@ class GitlabNet
response = http.start { http.request(request) } response = http.start { http.request(request) }
rescue => e rescue => e
$logger.warn "Failed to connect to internal API <#{method.to_s.upcase} #{url}>: #{e.inspect}" $logger.warn "Failed to connect to internal API <#{method.to_s.upcase} #{url}>: #{e.inspect}"
raise ApiUnreachableError raise ApiUnreachableError
end end
if response.code == "200" if response.code == "200"
......
...@@ -20,11 +20,13 @@ class GitlabPostReceive ...@@ -20,11 +20,13 @@ class GitlabPostReceive
begin begin
broadcast_message = GitlabNet.new.broadcast_message broadcast_message = GitlabNet.new.broadcast_message
if broadcast_message
if broadcast_message.has_key?("message")
puts puts
print_broadcast_message(broadcast_message["message"]) print_broadcast_message(broadcast_message["message"])
end end
rescue GitlabNet::ApiUnreachableError rescue GitlabNet::ApiUnreachableError
nil
end end
end end
......
...@@ -70,7 +70,7 @@ describe GitlabNet, vcr: true do ...@@ -70,7 +70,7 @@ describe GitlabNet, vcr: true do
it 'should return nil' do it 'should return nil' do
VCR.use_cassette("broadcast_message-none") do VCR.use_cassette("broadcast_message-none") do
result = gitlab_net.broadcast_message result = gitlab_net.broadcast_message
result.should == nil result.should == {}
end end
end end
end end
...@@ -125,7 +125,7 @@ describe GitlabNet, vcr: true do ...@@ -125,7 +125,7 @@ describe GitlabNet, vcr: true do
it "raises an exception if the connection fails" do it "raises an exception if the connection fails" do
Net::HTTP.any_instance.stub(:request).and_raise(StandardError) Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
expect { expect {
gitlab_net.check_access('git-upload-pack', 'gitlab/gitlabhq.git', 'user-1', changes) gitlab_net.check_access('git-upload-pack', 'gitlab/gitlabhq.git', 'user-1', changes)
}.to raise_error(GitlabNet::ApiUnreachableError) }.to raise_error(GitlabNet::ApiUnreachableError)
end end
......
...@@ -15,7 +15,7 @@ http_interactions: ...@@ -15,7 +15,7 @@ http_interactions:
- Ruby - Ruby
response: response:
status: status:
code: 404 code: 200
message: Not Found message: Not Found
headers: headers:
Server: Server:
...@@ -32,7 +32,7 @@ http_interactions: ...@@ -32,7 +32,7 @@ http_interactions:
- 200 OK - 200 OK
body: body:
encoding: UTF-8 encoding: UTF-8
string: '{"message":"404 Not Found"}' string: '{}'
http_version: http_version:
recorded_at: Sat, 07 Feb 2015 16:45:35 GMT recorded_at: Sat, 07 Feb 2015 16:45:35 GMT
recorded_with: VCR 2.4.0 recorded_with: VCR 2.4.0
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