Commit f162433a authored by Marius Bobin's avatar Marius Bobin

Use Gitlab::HTTP.try_get to find commit_status from Buildkite

parent cf586958
...@@ -73,10 +73,10 @@ class BuildkiteService < CiService ...@@ -73,10 +73,10 @@ class BuildkiteService < CiService
end end
def calculate_reactive_cache(sha, ref) def calculate_reactive_cache(sha, ref)
response = Gitlab::HTTP.get(commit_status_path(sha), verify: false) response = Gitlab::HTTP.try_get(commit_status_path(sha), request_options)
status = status =
if response.code == 200 && response['status'] if response&.code == 200 && response['status']
response['status'] response['status']
else else
:error :error
...@@ -117,4 +117,8 @@ class BuildkiteService < CiService ...@@ -117,4 +117,8 @@ class BuildkiteService < CiService
ENDPOINT ENDPOINT
end end
end end
def request_options
{ verify: false, extra_log_info: { project_id: project_id } }
end
end end
...@@ -84,6 +84,10 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do ...@@ -84,6 +84,10 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
describe '#calculate_reactive_cache' do describe '#calculate_reactive_cache' do
describe '#commit_status' do describe '#commit_status' do
let(:buildkite_full_url) do
'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123'
end
subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] } subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] }
it 'sets commit status to :error when status is 500' do it 'sets commit status to :error when status is 500' do
...@@ -103,13 +107,25 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do ...@@ -103,13 +107,25 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
is_expected.to eq('Great Success') is_expected.to eq('Great Success')
end end
Gitlab::HTTP::HTTP_ERRORS.each do |http_error|
it "sets commit status to :error with a #{http_error.name} error" do
WebMock.stub_request(:get, buildkite_full_url)
.to_raise(http_error)
expect(Gitlab::ErrorTracking)
.to receive(:log_exception)
.with(instance_of(http_error), project_id: project.id)
is_expected.to eq(:error)
end
end
end end
end end
end end
def stub_request(status: 200, body: nil) def stub_request(status: 200, body: nil)
body ||= %q({"status":"success"}) body ||= %q({"status":"success"})
buildkite_full_url = 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123'
stub_full_request(buildkite_full_url) stub_full_request(buildkite_full_url)
.to_return(status: status, .to_return(status: status,
......
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