As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 8ab4228b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Improve broadcast message logic

Expect broadcast message API endpoint to return 200 with empty JSON if
no broadcast messages available
parent b0979371
No related branches found
No related tags found
No related merge requests found
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
Loading
Loading
2.5.0
2.5.1
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
Loading
Loading
@@ -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"
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ http_interactions:
- Ruby
response:
status:
code: 404
code: 200
message: Not Found
headers:
Server:
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment