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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
17c32ee8
Commit
17c32ee8
authored
Jun 01, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factorize duplicated code into a method in BambooService and update specs
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
46f3cd7c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
26 deletions
+23
-26
app/models/project_services/bamboo_service.rb
app/models/project_services/bamboo_service.rb
+17
-20
spec/models/project_services/bamboo_service_spec.rb
spec/models/project_services/bamboo_service_spec.rb
+6
-6
No files found.
app/models/project_services/bamboo_service.rb
View file @
17c32ee8
...
@@ -59,18 +59,7 @@ class BambooService < CiService
...
@@ -59,18 +59,7 @@ class BambooService < CiService
end
end
def
build_info
(
sha
)
def
build_info
(
sha
)
url
=
URI
.
join
(
"
#{
bamboo_url
}
/"
,
"rest/api/latest/result?label=
#{
sha
}
"
).
to_s
@response
=
get_path
(
"rest/api/latest/result?label=
#{
sha
}
"
)
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
end
end
def
build_page
(
sha
,
ref
)
def
build_page
(
sha
,
ref
)
...
@@ -110,19 +99,27 @@ class BambooService < CiService
...
@@ -110,19 +99,27 @@ class BambooService < CiService
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
# Bamboo requires a GET and does take authentification
get_path
(
"updateAndBuild.action?buildKey=
#{
build_key
}
"
)
url
=
URI
.
join
(
"
#{
bamboo_url
}
/"
,
"updateAndBuild.action?buildKey=
#{
build_key
}
"
).
to_s
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?
if
username
.
blank?
&&
password
.
blank?
HTTParty
.
get
(
url
,
verify:
false
)
HTTParty
.
get
(
url
,
verify:
false
)
else
else
url
<<
'&os_authType=basic'
url
<<
'&os_authType=basic'
auth
=
{
HTTParty
.
get
(
url
,
verify:
false
,
username:
username
,
basic_auth:
{
password:
password
username:
username
,
}
password:
password
HTTParty
.
get
(
url
,
verify:
false
,
basic_auth:
auth
)
}
)
end
end
end
end
end
end
spec/models/project_services/bamboo_service_spec.rb
View file @
17c32ee8
...
@@ -126,25 +126,25 @@ describe BambooService, models: true do
...
@@ -126,25 +126,25 @@ describe BambooService, models: true do
it
'returns a specific URL when status is 500'
do
it
'returns a specific URL when status is 500'
do
stub_request
(
status:
500
)
stub_request
(
status:
500
)
expect
(
service
.
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com/browse/foo'
)
expect
(
service
.
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com/b
amboo/b
rowse/foo'
)
end
end
it
'returns a specific URL when response has no results'
do
it
'returns a specific URL when response has no results'
do
stub_request
(
body:
%Q({"results":{"results":{"size":"0"}}})
)
stub_request
(
body:
%Q({"results":{"results":{"size":"0"}}})
)
expect
(
service
.
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com/browse/foo'
)
expect
(
service
.
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com/b
amboo/b
rowse/foo'
)
end
end
it
'returns a build URL when bamboo_url has no trailing slash'
do
it
'returns a build URL when bamboo_url has no trailing slash'
do
stub_request
(
body:
%Q({"results":{"results":{"result":{"planResultKey":{"key":"42"}}}}})
)
stub_request
(
body:
%Q({"results":{"results":{"result":{"planResultKey":{"key":"42"}}}}})
)
expect
(
service
(
bamboo_url:
'http://gitlab.com
'
).
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com
/browse/42'
)
expect
(
service
(
bamboo_url:
'http://gitlab.com
/bamboo'
).
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com/bamboo
/browse/42'
)
end
end
it
'returns a build URL when bamboo_url has a trailing slash'
do
it
'returns a build URL when bamboo_url has a trailing slash'
do
stub_request
(
body:
%Q({"results":{"results":{"result":{"planResultKey":{"key":"42"}}}}})
)
stub_request
(
body:
%Q({"results":{"results":{"result":{"planResultKey":{"key":"42"}}}}})
)
expect
(
service
(
bamboo_url:
'http://gitlab.com/
'
).
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com
/browse/42'
)
expect
(
service
(
bamboo_url:
'http://gitlab.com/
bamboo/'
).
build_page
(
'123'
,
'unused'
)).
to
eq
(
'http://gitlab.com/bamboo
/browse/42'
)
end
end
end
end
...
@@ -192,7 +192,7 @@ describe BambooService, models: true do
...
@@ -192,7 +192,7 @@ describe BambooService, models: true do
end
end
end
end
def
service
(
bamboo_url:
'http://gitlab.com'
)
def
service
(
bamboo_url:
'http://gitlab.com
/bamboo
'
)
described_class
.
create
(
described_class
.
create
(
project:
create
(
:empty_project
),
project:
create
(
:empty_project
),
properties:
{
properties:
{
...
@@ -205,7 +205,7 @@ describe BambooService, models: true do
...
@@ -205,7 +205,7 @@ describe BambooService, models: true do
end
end
def
stub_request
(
status:
200
,
body:
nil
,
build_state:
'success'
)
def
stub_request
(
status:
200
,
body:
nil
,
build_state:
'success'
)
bamboo_full_url
=
'http://mic:password@gitlab.com/rest/api/latest/result?label=123&os_authType=basic'
bamboo_full_url
=
'http://mic:password@gitlab.com/
bamboo/
rest/api/latest/result?label=123&os_authType=basic'
body
||=
%Q({"results":{"results":{"result":{"buildState":"
#{
build_state
}
"}}}})
body
||=
%Q({"results":{"results":{"result":{"buildState":"
#{
build_state
}
"}}}})
WebMock
.
stub_request
(
:get
,
bamboo_full_url
).
to_return
(
WebMock
.
stub_request
(
:get
,
bamboo_full_url
).
to_return
(
...
...
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