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