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
07b3eceb
Commit
07b3eceb
authored
Jan 12, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ReactiveCaching in the JenkinsDeprecatedService
parent
bf497b14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
20 deletions
+38
-20
app/models/project_services/jenkins_deprecated_service.rb
app/models/project_services/jenkins_deprecated_service.rb
+13
-1
spec/models/project_services/jenkins_deprecated_service_spec.rb
...odels/project_services/jenkins_deprecated_service_spec.rb
+25
-19
No files found.
app/models/project_services/jenkins_deprecated_service.rb
View file @
07b3eceb
require
'uri'
class
JenkinsDeprecatedService
<
CiService
include
ReactiveService
prop_accessor
:project_url
boolean_accessor
:multiproject_enabled
boolean_accessor
:pass_unstable
...
...
@@ -61,6 +63,10 @@ class JenkinsDeprecatedService < CiService
end
end
def
commit_status
(
sha
,
ref
=
nil
)
with_reactive_cache
(
sha
,
ref
)
{
|
cached
|
cached
[
:commit_status
]
}
end
# When multi-project is enabled we need to have a different URL. Rather than
# relying on the user to provide the proper URL depending on multi-project
# we just parse the URL and make sure it's how we want it.
...
...
@@ -69,7 +75,13 @@ class JenkinsDeprecatedService < CiService
URI
.
join
(
url
,
'/job'
).
to_s
end
def
commit_status
(
sha
,
ref
=
nil
)
def
calculate_reactive_cache
(
sha
,
ref
)
{
commit_status:
read_commit_status
(
sha
,
ref
)
}
end
private
def
read_commit_status
(
sha
,
ref
)
parsed_url
=
URI
.
parse
(
build_page
(
sha
,
ref
))
if
parsed_url
.
userinfo
.
blank?
...
...
spec/models/project_services/jenkins_deprecated_service_spec.rb
View file @
07b3eceb
require
'spec_helper'
describe
JenkinsDeprecatedService
do
describe
JenkinsDeprecatedService
,
caching:
true
do
include
ReactiveCachingHelpers
describe
"Associations"
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
...
...
@@ -16,42 +18,46 @@ describe JenkinsDeprecatedService do
eos
end
describe
:commit_status
do
describe
'#calculate_reactive_cache'
do
let
(
:pass_unstable
)
{
'0'
}
before
do
@service
=
JenkinsDeprecatedService
.
new
allow
(
@service
).
to
receive_messages
(
service_hook:
true
,
project_url:
'http://jenkins.gitlab.org/job/2'
,
multiproject_enabled:
'0'
,
pass_unstable:
'0'
,
pass_unstable:
pass_unstable
,
token:
'verySecret'
)
end
statuses
=
{
'blue.png'
=>
'success'
,
'yellow.png'
=>
'failed'
,
'red.png'
=>
'failed'
,
'aborted.png'
=>
'failed'
,
'blue-anime.gif'
=>
'running'
,
'grey.png'
=>
'pending'
}
statuses
.
each
do
|
icon
,
state
|
it
"has a status of
#{
state
}
when the icon
#{
icon
}
exists."
do
it
"has a
commit_
status of
#{
state
}
when the icon
#{
icon
}
exists."
do
stub_request
(
:get
,
"http://jenkins.gitlab.org/job/2/scm/bySHA1/2ab7834c"
).
to_return
(
status:
200
,
body:
status_body_for_icon
(
icon
),
headers:
{})
expect
(
@service
.
commit_status
(
"2ab7834c"
,
'master'
)).
to
eq
(
state
)
expect
(
@service
.
calculate_reactive_cache
(
'2ab7834c'
,
'master'
)).
to
eq
(
commit_status:
state
)
end
end
end
describe
'commit status with passing unstable'
do
before
do
@service
=
JenkinsDeprecatedService
.
new
allow
(
@service
).
to
receive_messages
(
service_hook:
true
,
project_url:
'http://jenkins.gitlab.org/job/2'
,
multiproject_enabled:
'0'
,
pass_unstable:
'1'
,
token:
'verySecret'
)
context
'with passing unstable'
do
let
(
:pass_unstable
)
{
'1'
}
it
'has a commit_status of success when the icon yellow exists'
do
stub_request
(
:get
,
"http://jenkins.gitlab.org/job/2/scm/bySHA1/2ab7834c"
).
to_return
(
status:
200
,
body:
status_body_for_icon
(
'yellow.png'
),
headers:
{})
expect
(
@service
.
calculate_reactive_cache
(
'2ab7834c'
,
'master'
)).
to
eq
(
commit_status:
'success'
)
end
end
end
describe
'#commit_status'
do
subject
(
:service
)
{
described_class
.
new
(
project_id:
666
)
}
it
'returns the contents of the reactive cache'
do
stub_reactive_cache
(
service
,
{
commit_status:
'foo'
},
'sha'
,
'ref'
)
it
"has a status of success when the icon yellow exists."
do
stub_request
(
:get
,
"http://jenkins.gitlab.org/job/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'
)
expect
(
service
.
commit_status
(
'sha'
,
'ref'
)).
to
eq
(
'foo'
)
end
end
...
...
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