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
Tatuya Kamada
gitlab-ce
Commits
940f900f
Commit
940f900f
authored
Sep 06, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change response for /ci/api/v1/builds/register.json from 404 to 204
parent
404f438f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
20 deletions
+44
-20
lib/api/helpers.rb
lib/api/helpers.rb
+4
-0
lib/ci/api/builds.rb
lib/ci/api/builds.rb
+1
-1
lib/ci/api/helpers.rb
lib/ci/api/helpers.rb
+8
-0
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+31
-19
No files found.
lib/api/helpers.rb
View file @
940f900f
...
...
@@ -269,6 +269,10 @@ module API
render_api_error!
(
'304 Not Modified'
,
304
)
end
def
no_content!
render_api_error!
(
'204 No Content'
,
204
)
end
def
render_validation_error!
(
model
)
if
model
.
errors
.
any?
render_api_error!
(
model
.
errors
.
messages
||
'400 Bad Request'
,
400
)
...
...
lib/ci/api/builds.rb
View file @
940f900f
...
...
@@ -27,7 +27,7 @@ module Ci
else
Gitlab
::
Metrics
.
add_event
(
:build_not_found
)
not_found!
build_
not_found!
end
end
...
...
lib/ci/api/helpers.rb
View file @
940f900f
...
...
@@ -32,6 +32,14 @@ module Ci
end
end
def
build_not_found!
if
headers
[
'User-Agent'
].
match
(
/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /
)
no_content!
else
not_found!
end
end
def
current_runner
@runner
||=
Runner
.
find_by_token
(
params
[
:token
].
to_s
)
end
...
...
spec/requests/ci/api/builds_spec.rb
View file @
940f900f
...
...
@@ -15,6 +15,25 @@ describe Ci::API::API do
describe
"POST /builds/register"
do
let!
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'spinach'
,
stage:
'test'
,
stage_idx:
0
)
}
let
(
:user_agent
)
{
'gitlab-ci-multi-runner 1.5.2 (1-5-stable; go1.6.3; linux/amd64)'
}
shared_examples
'no builds available'
do
context
'when runner sends version in User-Agent'
do
context
'for stable version'
do
it
{
expect
(
response
).
to
have_http_status
(
204
)
}
end
context
'for beta version'
do
let
(
:user_agent
)
{
'gitlab-ci-multi-runner 1.6.0~beta.167.g2b2bacc (1-5-stable; go1.6.3; linux/amd64)'
}
it
{
expect
(
response
).
to
have_http_status
(
204
)
}
end
end
context
"when runner doesn't send version in User-Agent"
do
let
(
:user_agent
)
{
'Go-http-client/1.1'
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
end
it
"starts a build"
do
register_builds
info:
{
platform: :darwin
}
...
...
@@ -33,36 +52,30 @@ describe Ci::API::API do
context
'when builds are finished'
do
before
do
build
.
success
end
it
"returns 404 error if no builds for specific runner"
do
register_builds
expect
(
response
).
to
have_http_status
(
404
)
end
it_behaves_like
'no builds available'
end
context
'for other project with builds'
do
before
do
build
.
success
create
(
:ci_build
,
:pending
)
end
it
"returns 404 error if no builds for shared runner"
do
register_builds
expect
(
response
).
to
have_http_status
(
404
)
end
it_behaves_like
'no builds available'
end
context
'for shared runner'
do
let
(
:shared_runner
)
{
create
(
:ci_runner
,
token:
"SharedRunner"
)
}
it
"should return 404 error if no builds for shared runner"
do
before
do
register_builds
shared_runner
.
token
expect
(
response
).
to
have_http_status
(
404
)
end
it_behaves_like
'no builds available'
end
context
'for triggered build'
do
...
...
@@ -136,18 +149,17 @@ describe Ci::API::API do
end
context
'when runner is not allowed to pick untagged builds'
do
before
{
runner
.
update_column
(
:run_untagged
,
false
)
}
it
'does not pick build'
do
before
do
runner
.
update_column
(
:run_untagged
,
false
)
register_builds
expect
(
response
).
to
have_http_status
404
end
it_behaves_like
'no builds available'
end
end
def
register_builds
(
token
=
runner
.
token
,
**
params
)
post
ci_api
(
"/builds/register"
),
params
.
merge
(
token:
token
)
post
ci_api
(
"/builds/register"
),
params
.
merge
(
token:
token
)
,
{
'User-Agent'
=>
user_agent
}
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