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
Boxiang Sun
gitlab-ce
Commits
0e6fdf06
Commit
0e6fdf06
authored
Jan 24, 2019
by
Alex Lossent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support polymorphism of Bamboo REST API results
It may return single result or an array of results
parent
4dd8740c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
14 deletions
+49
-14
app/models/project_services/bamboo_service.rb
app/models/project_services/bamboo_service.rb
+22
-10
changelogs/unreleased/24680-support-bamboo-api-polymorphism.yml
...logs/unreleased/24680-support-bamboo-api-polymorphism.yml
+5
-0
spec/models/project_services/bamboo_service_spec.rb
spec/models/project_services/bamboo_service_spec.rb
+22
-4
No files found.
app/models/project_services/bamboo_service.rb
View file @
0e6fdf06
...
@@ -80,19 +80,27 @@ class BambooService < CiService
...
@@ -80,19 +80,27 @@ class BambooService < CiService
private
private
def
get_build_result_index
def
get_build_result
(
response
)
# When Bamboo returns multiple results for a given changeset, arbitrarily assume the most relevant result to be the last one.
return
if
response
.
code
!=
200
-
1
# May be nil if no result, a single result hash, or an array if multiple results for a given changeset.
result
=
response
.
dig
(
'results'
,
'results'
,
'result'
)
# In case of multiple results, arbitrarily assume the last one is the most relevant.
return
result
.
last
if
result
.
is_a?
(
Array
)
result
end
end
def
read_build_page
(
response
)
def
read_build_page
(
response
)
result
=
get_build_result
(
response
)
key
=
key
=
if
res
ponse
.
code
!=
200
||
response
.
dig
(
'results'
,
'results'
,
'size'
)
==
'0'
if
res
ult
.
blank?
# If actual build link can't be determined, send user to build summary page.
# If actual build link can't be determined, send user to build summary page.
build_key
build_key
else
else
# If actual build link is available, go to build result page.
# If actual build link is available, go to build result page.
res
ponse
.
dig
(
'results'
,
'results'
,
'result'
,
get_build_result_index
,
'planResultKey'
,
'key'
)
res
ult
.
dig
(
'planResultKey'
,
'key'
)
end
end
build_url
(
"browse/
#{
key
}
"
)
build_url
(
"browse/
#{
key
}
"
)
...
@@ -101,12 +109,16 @@ class BambooService < CiService
...
@@ -101,12 +109,16 @@ class BambooService < CiService
def
read_commit_status
(
response
)
def
read_commit_status
(
response
)
return
:error
unless
response
.
code
==
200
||
response
.
code
==
404
return
:error
unless
response
.
code
==
200
||
response
.
code
==
404
status
=
if
response
.
code
==
404
||
response
.
dig
(
'results'
,
'results'
,
'size'
)
==
'0'
result
=
get_build_result
(
response
)
status
=
if
result
.
blank?
'Pending'
'Pending'
else
else
response
.
dig
(
'results'
,
'results'
,
'result'
,
get_build_result_index
,
'buildState'
)
result
.
dig
(
'buildState'
)
end
end
return
:error
unless
status
.
present?
if
status
.
include?
(
'Success'
)
if
status
.
include?
(
'Success'
)
'success'
'success'
elsif
status
.
include?
(
'Failed'
)
elsif
status
.
include?
(
'Failed'
)
...
...
changelogs/unreleased/24680-support-bamboo-api-polymorphism.yml
0 → 100644
View file @
0e6fdf06
---
title
:
"
Support
bamboo
api
polymorphism"
merge_request
:
24680
author
:
Alex Lossent
type
:
fixed
\ No newline at end of file
spec/models/project_services/bamboo_service_spec.rb
View file @
0e6fdf06
...
@@ -144,7 +144,7 @@ describe BambooService, :use_clean_rails_memory_store_caching do
...
@@ -144,7 +144,7 @@ describe BambooService, :use_clean_rails_memory_store_caching do
end
end
end
end
describe
'#calculate_reactive_cache
'
do
shared_examples
'reactive cache calculation
'
do
context
'#build_page'
do
context
'#build_page'
do
subject
{
service
.
calculate_reactive_cache
(
'123'
,
'unused'
)[
:build_page
]
}
subject
{
service
.
calculate_reactive_cache
(
'123'
,
'unused'
)[
:build_page
]
}
...
@@ -155,7 +155,7 @@ describe BambooService, :use_clean_rails_memory_store_caching do
...
@@ -155,7 +155,7 @@ describe BambooService, :use_clean_rails_memory_store_caching do
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:
bamboo_response
(
size:
0
))
stub_request
(
body:
%q({"results":{"results":{"size":"0"}}}
)
)
is_expected
.
to
eq
(
'http://gitlab.com/bamboo/browse/foo'
)
is_expected
.
to
eq
(
'http://gitlab.com/bamboo/browse/foo'
)
end
end
...
@@ -224,6 +224,24 @@ describe BambooService, :use_clean_rails_memory_store_caching do
...
@@ -224,6 +224,24 @@ describe BambooService, :use_clean_rails_memory_store_caching do
end
end
end
end
describe
'#calculate_reactive_cache'
do
context
'when Bamboo API returns single result'
do
let
(
:bamboo_response_template
)
do
%q({"results":{"results":{"size":"1","result":{"buildState":"%{build_state}","planResultKey":{"key":"42"}}}}})
end
it_behaves_like
'reactive cache calculation'
end
context
'when Bamboo API returns an array of results and we only consider the last one'
do
let
(
:bamboo_response_template
)
do
%q({"results":{"results":{"size":"2","result":[{"buildState":"%{build_state}","planResultKey":{"key":"41"}},{"buildState":"%{build_state}","planResultKey":{"key":"42"}}]}}})
end
it_behaves_like
'reactive cache calculation'
end
end
def
stub_update_and_build_request
(
status:
200
,
body:
nil
)
def
stub_update_and_build_request
(
status:
200
,
body:
nil
)
bamboo_full_url
=
'http://gitlab.com/bamboo/updateAndBuild.action?buildKey=foo&os_authType=basic'
bamboo_full_url
=
'http://gitlab.com/bamboo/updateAndBuild.action?buildKey=foo&os_authType=basic'
...
@@ -244,8 +262,8 @@ describe BambooService, :use_clean_rails_memory_store_caching do
...
@@ -244,8 +262,8 @@ describe BambooService, :use_clean_rails_memory_store_caching do
).
with
(
basic_auth:
%w(mic password)
)
).
with
(
basic_auth:
%w(mic password)
)
end
end
def
bamboo_response
(
result_key:
42
,
build_state:
'success'
,
size:
1
)
def
bamboo_response
(
build_state:
'success'
)
# reference: https://docs.atlassian.com/atlassian-bamboo/REST/6.2.5/#d2e786
# reference: https://docs.atlassian.com/atlassian-bamboo/REST/6.2.5/#d2e786
%Q({"results":{"results":{"size":"
#{
size
}
","result":[{"buildState":"
#{
build_state
}
","planResultKey":{"key":"
#{
result_key
}
"}}]}}})
bamboo_response_template
%
{
build_state:
build_state
}
end
end
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