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
46b83f06
Commit
46b83f06
authored
Aug 25, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an error where we were unable to create a CommitStatus for running state
parent
45afdbef
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
36 deletions
+58
-36
CHANGELOG
CHANGELOG
+1
-0
lib/api/commit_statuses.rb
lib/api/commit_statuses.rb
+28
-26
spec/requests/api/commit_statuses_spec.rb
spec/requests/api/commit_statuses_spec.rb
+29
-10
No files found.
CHANGELOG
View file @
46b83f06
...
...
@@ -121,6 +121,7 @@ v 8.12.0 (unreleased)
- Add notification_settings API calls !5632 (mahcsig)
v 8.11.6 (unreleased)
- Fix an error where we were unable to create a CommitStatus for running state
v 8.11.5
- Optimize branch lookups and force a repository reload for Repository#find_branch. !6087
...
...
lib/api/commit_statuses.rb
View file @
46b83f06
...
...
@@ -37,7 +37,7 @@ module API
# id (required) - The ID of a project
# sha (required) - The commit hash
# ref (optional) - The ref
# state (required) - The state of the status. Can be: pending, running, success,
error or failure
# state (required) - The state of the status. Can be: pending, running, success,
failed or canceled
# target_url (optional) - The target URL to associate with this status
# description (optional) - A short description of the status
# name or context (optional) - A string label to differentiate this status from the status of other systems. Default: "default"
...
...
@@ -46,7 +46,7 @@ module API
post
':id/statuses/:sha'
do
authorize!
:create_commit_status
,
user_project
required_attributes!
[
:state
]
attrs
=
attributes_for_keys
[
:
ref
,
:target_url
,
:description
,
:context
,
:name
]
attrs
=
attributes_for_keys
[
:
target_url
,
:description
]
commit
=
@project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
...
...
@@ -58,36 +58,38 @@ module API
# the first found branch on that commit
ref
=
params
[
:ref
]
unless
ref
branches
=
@project
.
repository
.
branch_names_contains
(
commit
.
sha
)
not_found!
'References for commit'
if
branches
.
none?
ref
=
branches
.
first
end
ref
||=
@project
.
repository
.
branch_names_contains
(
commit
.
sha
).
first
not_found!
'References for commit'
unless
ref
name
=
params
[
:name
]
||
params
[
:context
]
||
'default'
pipeline
=
@project
.
ensure_pipeline
(
ref
,
commit
.
sha
,
current_user
)
name
=
params
[
:name
]
||
params
[
:context
]
status
=
GenericCommitStatus
.
running_or_pending
.
find_by
(
pipeline:
pipeline
,
name:
name
,
ref:
params
[
:ref
])
status
||=
GenericCommitStatus
.
new
(
project:
@project
,
pipeline:
pipeline
,
user:
current_user
)
status
.
update
(
attrs
)
status
=
GenericCommitStatus
.
running_or_pending
.
find_or_initialize_by
(
project:
@project
,
pipeline:
pipeline
,
user:
current_user
,
name:
name
,
ref:
ref
)
status
.
attributes
=
attrs
begin
case
params
[
:state
].
to_s
when
'pending'
status
.
enqueue!
when
'running'
status
.
run
status
.
enqueue
status
.
run!
when
'success'
status
.
success
status
.
success!
when
'failed'
status
.
drop
status
.
drop!
when
'canceled'
status
.
cancel
status
.
cancel!
else
status
.
status
=
params
[
:state
].
to_s
render_api_error!
(
'invalid state'
,
400
)
end
if
status
.
save
present
status
,
with:
Entities
::
CommitStatus
els
e
render_
validation_error!
(
status
)
rescue
StateMachines
::
InvalidTransition
=>
e
render_
api_error!
(
e
.
message
,
400
)
end
end
end
...
...
spec/requests/api/commit_statuses_spec.rb
View file @
46b83f06
...
...
@@ -117,19 +117,38 @@ describe API::CommitStatuses, api: true do
let
(
:post_url
)
{
"/projects/
#{
project
.
id
}
/statuses/
#{
sha
}
"
}
context
'developer user'
do
context
'only required parameters'
do
before
{
post
api
(
post_url
,
developer
),
state:
'success'
}
%w[pending running success failed canceled]
.
each
do
|
status
|
context
"for
#{
status
}
"
do
context
'uses only required parameters'
do
it
'creates commit status'
do
post
api
(
post_url
,
developer
),
state:
status
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'sha'
]).
to
eq
(
commit
.
id
)
expect
(
json_response
[
'status'
]).
to
eq
(
'success'
)
expect
(
json_response
[
'status'
]).
to
eq
(
status
)
expect
(
json_response
[
'name'
]).
to
eq
(
'default'
)
expect
(
json_response
[
'ref'
]).
to
be_nil
expect
(
json_response
[
'ref'
]).
not_to
be_empty
expect
(
json_response
[
'target_url'
]).
to
be_nil
expect
(
json_response
[
'description'
]).
to
be_nil
end
end
end
end
context
'transitions status from pending'
do
before
do
post
api
(
post_url
,
developer
),
state:
'pending'
end
%w[running success failed canceled]
.
each
do
|
status
|
it
"to
#{
status
}
"
do
expect
{
post
api
(
post_url
,
developer
),
state:
status
}.
not_to
change
{
CommitStatus
.
count
}
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'status'
]).
to
eq
(
status
)
end
end
end
context
'with all optional parameters'
do
before
do
...
...
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