diff options
author | Rémy Coutable <remy@rymai.me> | 2016-06-01 16:43:40 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-06-14 10:07:37 +0200 |
commit | 17c32ee8d0b2dafa61b3f509d48f7ee8a8dbea14 (patch) | |
tree | f6208636de64b57b1d1534c75f7d87eda0ec1848 /app/models | |
parent | 46f3cd7c65b871d4efa6c33fbfccbc01fdf36649 (diff) | |
download | gitlab-ce-17c32ee8d0b2dafa61b3f509d48f7ee8a8dbea14.tar.gz |
Factorize duplicated code into a method in BambooService and update specs
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project_services/bamboo_service.rb | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/app/models/project_services/bamboo_service.rb b/app/models/project_services/bamboo_service.rb index cb215b595f5..b5c76e4d4fe 100644 --- a/app/models/project_services/bamboo_service.rb +++ b/app/models/project_services/bamboo_service.rb @@ -59,18 +59,7 @@ class BambooService < CiService end def build_info(sha) - url = URI.join("#{bamboo_url}/", "rest/api/latest/result?label=#{sha}").to_s - - if username.blank? && password.blank? - @response = HTTParty.get(url, verify: false) - else - url << '&os_authType=basic' - auth = { - username: username, - password: password - } - @response = HTTParty.get(url, verify: false, basic_auth: auth) - end + @response = get_path("rest/api/latest/result?label=#{sha}") end def build_page(sha, ref) @@ -110,19 +99,27 @@ class BambooService < CiService def execute(data) 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 + get_path("updateAndBuild.action?buildKey=#{build_key}") + end + + private + + def build_url(path) + URI.join("#{bamboo_url}/", path).to_s + end + + def get_path(path) + url = build_url(path) if username.blank? && password.blank? HTTParty.get(url, verify: false) else url << '&os_authType=basic' - auth = { - username: username, - password: password - } - HTTParty.get(url, verify: false, basic_auth: auth) + HTTParty.get(url, verify: false, + basic_auth: { + username: username, + password: password + }) end - end end |