Commit 645ca051 authored by charlie ablett's avatar charlie ablett

Merge branch 'calculate-reactive-cache-with-try-get-for-buildkite-ci' into 'master'

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

See merge request gitlab-org/gitlab!27881
parents 76948de3 f162433a
......@@ -73,10 +73,10 @@ class BuildkiteService < CiService
end
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 =
if response.code == 200 && response['status']
if response&.code == 200 && response['status']
response['status']
else
:error
......@@ -117,4 +117,8 @@ class BuildkiteService < CiService
ENDPOINT
end
end
def request_options
{ verify: false, extra_log_info: { project_id: project_id } }
end
end
......@@ -84,6 +84,10 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
describe '#calculate_reactive_cache' 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] }
it 'sets commit status to :error when status is 500' do
......@@ -103,13 +107,25 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
is_expected.to eq('Great Success')
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
def stub_request(status: 200, body: nil)
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)
.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