Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f80ca51b
Commit
f80ca51b
authored
Oct 01, 2015
by
Chris Rohr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up conditional syntax
parent
6c6c7c3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
8 deletions
+33
-8
app/models/project_services/jenkins_service.rb
app/models/project_services/jenkins_service.rb
+12
-6
spec/models/project_services/jenkins_service_spec.rb
spec/models/project_services/jenkins_service_spec.rb
+21
-2
No files found.
app/models/project_services/jenkins_service.rb
View file @
f80ca51b
...
...
@@ -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'
...
...
spec/models/project_services/jenkins_service_spec.rb
View file @
f80ca51b
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment