Fix broken URI joining for bamboo_url with suffixes

If one had configured a `bamboo_url` like http://foo.bar/bamboo in the
previous implementation the plugin directed it's request i.e. to
http://foo.bar/rest/... instead of http://foo.bar/bamboo/rest/...

`URI.join` only works correctly, if the prefix URL has
  - at least one or more  trailing '/'
  - the appended parts are _not_ prefixed with '/'

The current implementation should work with all sorts of Bamboo base URLs.

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Benjamin Schmid 2016-05-30 12:30:35 +02:00 committed by Rémy Coutable
parent 84b07f7054
commit 46f3cd7c65
No known key found for this signature in database
GPG key ID: 46DF07E5CD9E96AB
2 changed files with 5 additions and 4 deletions

View file

@ -38,6 +38,7 @@ v 8.9.0 (unreleased)
- Add option to project to only allow merge requests to be merged if the build succeeds (Rui Santos)
- Fix issues filter when ordering by milestone
- Added artifacts:when to .gitlab-ci.yml - this requires GitLab Runner 1.3
- Bamboo Service: Fix missing credentials & URL handling when base URL contains a path (Benjamin Schmid)
- Todos will display target state if issuable target is 'Closed' or 'Merged'
- Fix bug when sorting issues by milestone due date and filtering by two or more labels
- Add support for using Yubikeys (U2F) for two-factor authentication

View file

@ -59,7 +59,7 @@ class BambooService < CiService
end
def build_info(sha)
url = URI.join(bamboo_url, "/rest/api/latest/result?label=#{sha}").to_s
url = URI.join("#{bamboo_url}/", "rest/api/latest/result?label=#{sha}").to_s
if username.blank? && password.blank?
@response = HTTParty.get(url, verify: false)
@ -78,11 +78,11 @@ class BambooService < CiService
if @response.code != 200 || @response['results']['results']['size'] == '0'
# If actual build link can't be determined, send user to build summary page.
URI.join(bamboo_url, "/browse/#{build_key}").to_s
URI.join("#{bamboo_url}/", "browse/#{build_key}").to_s
else
# If actual build link is available, go to build result page.
result_key = @response['results']['results']['result']['planResultKey']['key']
URI.join(bamboo_url, "/browse/#{result_key}").to_s
URI.join("#{bamboo_url}/", "browse/#{result_key}").to_s
end
end
@ -111,7 +111,7 @@ class BambooService < CiService
return unless supported_events.include?(data[:object_kind])
# Bamboo requires a GET and does take authentification
url = URI.join(bamboo_url, "/updateAndBuild.action?buildKey=#{build_key}").to_s
url = URI.join("#{bamboo_url}/", "updateAndBuild.action?buildKey=#{build_key}").to_s
if username.blank? && password.blank?
HTTParty.get(url, verify: false)