Fix Bamboo CI status not showing for branch plans
The original API that queries by label (`/rest/api/latest/result?label=#{sha1}`)
only works for results from main plans and not branch plans. The
`/rest/api/latest/result/byChangeset/#{sha1}` endpoint gives results from
branch plans but not for the first push to the branch. Subsequent pushes
work.
For more details, see https://jira.atlassian.com/browse/BAM-16121.
Closes #1355
This commit is contained in:
parent
70cf3bff18
commit
05a9c6b211
|
|
@ -67,11 +67,11 @@ class BambooService < CiService
|
|||
def execute(data)
|
||||
return unless supported_events.include?(data[:object_kind])
|
||||
|
||||
get_path("updateAndBuild.action?buildKey=#{build_key}")
|
||||
get_path("updateAndBuild.action", { buildKey: build_key })
|
||||
end
|
||||
|
||||
def calculate_reactive_cache(sha, ref)
|
||||
response = get_path("rest/api/latest/result?label=#{sha}")
|
||||
response = get_path("rest/api/latest/result/byChangeset/#{sha}")
|
||||
|
||||
{ build_page: read_build_page(response), commit_status: read_commit_status(response) }
|
||||
end
|
||||
|
|
@ -113,18 +113,20 @@ class BambooService < CiService
|
|||
URI.join("#{bamboo_url}/", path).to_s
|
||||
end
|
||||
|
||||
def get_path(path)
|
||||
def get_path(path, query_params = {})
|
||||
url = build_url(path)
|
||||
|
||||
if username.blank? && password.blank?
|
||||
Gitlab::HTTP.get(url, verify: false)
|
||||
Gitlab::HTTP.get(url, verify: false, query: query_params)
|
||||
else
|
||||
url << '&os_authType=basic'
|
||||
Gitlab::HTTP.get(url, verify: false,
|
||||
basic_auth: {
|
||||
username: username,
|
||||
password: password
|
||||
})
|
||||
query_params[:os_authType] = 'basic'
|
||||
Gitlab::HTTP.get(url,
|
||||
verify: false,
|
||||
query: query_params,
|
||||
basic_auth: {
|
||||
username: username,
|
||||
password: password
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix Bamboo CI status not showing for branch plans
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
||||
|
|
@ -120,6 +120,14 @@ describe BambooService, :use_clean_rails_memory_store_caching do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#execute' do
|
||||
it 'runs update and build action' do
|
||||
stub_update_and_build_request
|
||||
|
||||
subject.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#build_page' do
|
||||
it 'returns the contents of the reactive cache' do
|
||||
stub_reactive_cache(service, { build_page: 'foo' }, 'sha', 'ref')
|
||||
|
|
@ -216,10 +224,20 @@ describe BambooService, :use_clean_rails_memory_store_caching do
|
|||
end
|
||||
end
|
||||
|
||||
def stub_request(status: 200, body: nil)
|
||||
bamboo_full_url = 'http://gitlab.com/bamboo/rest/api/latest/result?label=123&os_authType=basic'
|
||||
def stub_update_and_build_request(status: 200, body: nil)
|
||||
bamboo_full_url = 'http://gitlab.com/bamboo/updateAndBuild.action?buildKey=foo&os_authType=basic'
|
||||
|
||||
WebMock.stub_request(:get, bamboo_full_url).to_return(
|
||||
stub_bamboo_request(bamboo_full_url, status, body)
|
||||
end
|
||||
|
||||
def stub_request(status: 200, body: nil)
|
||||
bamboo_full_url = 'http://gitlab.com/bamboo/rest/api/latest/result/byChangeset/123?os_authType=basic'
|
||||
|
||||
stub_bamboo_request(bamboo_full_url, status, body)
|
||||
end
|
||||
|
||||
def stub_bamboo_request(url, status, body)
|
||||
WebMock.stub_request(:get, url).to_return(
|
||||
status: status,
|
||||
headers: { 'Content-Type' => 'application/json' },
|
||||
body: body
|
||||
|
|
|
|||
Loading…
Reference in New Issue