Commit f80ca51b authored by Chris Rohr's avatar Chris Rohr

Cleaned up conditional syntax

parent 6c6c7c3c
......@@ -15,6 +15,7 @@
class JenkinsService < CiService
prop_accessor :project_url
prop_accessor :multiproject_enabled
prop_accessor :pass_unstable
validates :project_url, presence: true, if: :activated?
......@@ -49,7 +50,9 @@ class JenkinsService < CiService
[
{ type: 'text', name: 'project_url', placeholder: 'Jenkins project URL like http://jenkins.example.com/job/my-project/' },
{ type: 'checkbox', name: 'multiproject_enabled', title: "Multi-project setup enabled?",
help: "Multi-project mode is configured in Jenkins Gitlab Hook plugin." }
help: "Multi-project mode is configured in Jenkins Gitlab Hook plugin." },
{ type: 'checkbox', name: 'pass_unstable', title: 'Should unstable builds be treated as passing?',
help: 'Unstable builds will be treated as passing.'}
]
end
......@@ -57,12 +60,15 @@ class JenkinsService < CiService
self.multiproject_enabled == '1'
end
def pass_unstable?
self.pass_unstable == '1'
end
def build_page(sha, ref = nil)
if multiproject_enabled?
base_url = ref.nil? || ref == 'master' ? project_url : "#{project_url}_#{ref}"
base_url + "/scm/bySHA1/#{sha}"
if multiproject_enabled? && ref.present?
"#{project_url}_#{ref}/scm/bySHA1/#{sha}"
else
project_url + "/scm/bySHA1/#{sha}"
"#{project_url}/scm/bySHA1/#{sha}"
end
end
......@@ -83,7 +89,7 @@ class JenkinsService < CiService
if response.code == 200
# img.build-caption-status-icon for old jenkins version
src = Nokogiri.parse(response).css('img.build-caption-status-icon,.build-caption>img').first.attributes['src'].value
if src =~ /blue\.png$/
if src =~ /blue\.png$/ || (src =~ /yellow\.png/ && pass_unstable?)
'success'
elsif src =~ /(red|aborted|yellow)\.png$/
'failed'
......
......@@ -41,7 +41,8 @@ eos
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
multiproject_enabled: '1',
multiproject_enabled: '0',
pass_unstable: '0',
token: 'verySecret'
)
end
......@@ -55,6 +56,24 @@ eos
end
end
describe 'commit status with passing unstable' do
before do
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
multiproject_enabled: '0',
pass_unstable: '1',
token: 'verySecret'
)
end
it "should have a status of success when the icon yellow exists." do
stub_request(:get, "http://jenkins.gitlab.org/projects/2/scm/bySHA1/2ab7834c").to_return(status: 200, body: status_body_for_icon('yellow.png'), headers: {})
expect(@service.commit_status("2ab7834c", 'master')).to eq('success')
end
end
describe 'multiproject enabled' do
before do
@service = JenkinsService.new
......@@ -67,7 +86,7 @@ eos
end
describe :build_page do
it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://jenkins.gitlab.org/projects/2/scm/bySHA1/2ab7834c") }
it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://jenkins.gitlab.org/projects/2_master/scm/bySHA1/2ab7834c") }
end
describe :build_page_with_branch do
......
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