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
f162433a
Commit
f162433a
authored
Mar 24, 2020
by
Marius Bobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Gitlab::HTTP.try_get to find commit_status from Buildkite
parent
cf586958
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
app/models/project_services/buildkite_service.rb
app/models/project_services/buildkite_service.rb
+6
-2
spec/models/project_services/buildkite_service_spec.rb
spec/models/project_services/buildkite_service_spec.rb
+17
-1
No files found.
app/models/project_services/buildkite_service.rb
View file @
f162433a
...
...
@@ -73,10 +73,10 @@ class BuildkiteService < CiService
end
def
calculate_reactive_cache
(
sha
,
ref
)
response
=
Gitlab
::
HTTP
.
get
(
commit_status_path
(
sha
),
verify:
false
)
response
=
Gitlab
::
HTTP
.
try_get
(
commit_status_path
(
sha
),
request_options
)
status
=
if
response
.
code
==
200
&&
response
[
'status'
]
if
response
&
.
code
==
200
&&
response
[
'status'
]
response
[
'status'
]
else
:error
...
...
@@ -117,4 +117,8 @@ class BuildkiteService < CiService
ENDPOINT
end
end
def
request_options
{
verify:
false
,
extra_log_info:
{
project_id:
project_id
}
}
end
end
spec/models/project_services/buildkite_service_spec.rb
View file @
f162433a
...
...
@@ -84,6 +84,10 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
describe
'#calculate_reactive_cache'
do
describe
'#commit_status'
do
let
(
:buildkite_full_url
)
do
'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123'
end
subject
{
service
.
calculate_reactive_cache
(
'123'
,
'unused'
)[
:commit_status
]
}
it
'sets commit status to :error when status is 500'
do
...
...
@@ -103,13 +107,25 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
is_expected
.
to
eq
(
'Great Success'
)
end
Gitlab
::
HTTP
::
HTTP_ERRORS
.
each
do
|
http_error
|
it
"sets commit status to :error with a
#{
http_error
.
name
}
error"
do
WebMock
.
stub_request
(
:get
,
buildkite_full_url
)
.
to_raise
(
http_error
)
expect
(
Gitlab
::
ErrorTracking
)
.
to
receive
(
:log_exception
)
.
with
(
instance_of
(
http_error
),
project_id:
project
.
id
)
is_expected
.
to
eq
(
:error
)
end
end
end
end
end
def
stub_request
(
status:
200
,
body:
nil
)
body
||=
%q({"status":"success"})
buildkite_full_url
=
'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123'
stub_full_request
(
buildkite_full_url
)
.
to_return
(
status:
status
,
...
...
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