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
c7282f89
Commit
c7282f89
authored
Oct 14, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grapify the commit status API
parent
4b889dbb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
28 deletions
+29
-28
lib/api/commit_statuses.rb
lib/api/commit_statuses.rb
+27
-26
spec/requests/api/commit_statuses_spec.rb
spec/requests/api/commit_statuses_spec.rb
+2
-2
No files found.
lib/api/commit_statuses.rb
View file @
c7282f89
...
@@ -6,17 +6,17 @@ module API
...
@@ -6,17 +6,17 @@ module API
resource
:projects
do
resource
:projects
do
before
{
authenticate!
}
before
{
authenticate!
}
# Get a commit's statuses
desc
"Get a commit's statuses"
do
#
success
Entities
::
CommitStatus
# Parameters:
end
# id (required) - The ID of a project
params
do
# sha (required) - The commit hash
requires
:id
,
type:
String
,
desc:
'The ID of a project'
# ref (optional) - The ref
requires
:sha
,
type:
String
,
desc:
'The commit hash'
# stage (optional) - The stage
optional
:ref
,
type:
String
,
desc:
'The ref'
# name (optional) - The name
optional
:stage
,
type:
String
,
desc:
'The stage'
# all (optional) - Show all statuses, default: false
optional
:name
,
type:
String
,
desc:
'The name'
# Examples:
optional
:all
,
type:
String
,
desc:
'Show all statuses, default: false'
# GET /projects/:id/repository/commits/:sha/statuses
end
get
':id/repository/commits/:sha/statuses'
do
get
':id/repository/commits/:sha/statuses'
do
authorize!
(
:read_commit_status
,
user_project
)
authorize!
(
:read_commit_status
,
user_project
)
...
@@ -31,22 +31,23 @@ module API
...
@@ -31,22 +31,23 @@ module API
present
paginate
(
statuses
),
with:
Entities
::
CommitStatus
present
paginate
(
statuses
),
with:
Entities
::
CommitStatus
end
end
# Post status to commit
desc
'Post status to a commit'
do
#
success
Entities
::
CommitStatus
# Parameters:
end
# id (required) - The ID of a project
params
do
# sha (required) - The commit hash
requires
:id
,
type:
String
,
desc:
'The ID of a project'
# ref (optional) - The ref
requires
:sha
,
type:
String
,
desc:
'The commit hash'
# state (required) - The state of the status. Can be: pending, running, success, failed or canceled
requires
:state
,
type:
String
,
desc:
'The state of the status'
,
# target_url (optional) - The target URL to associate with this status
values:
[
'pending'
,
'running'
,
'success'
,
'failed'
,
'canceled'
]
# description (optional) - A short description of the status
optional
:ref
,
type:
String
,
desc:
'The ref'
# name or context (optional) - A string label to differentiate this status from the status of other systems. Default: "default"
optional
:target_url
,
type:
String
,
desc:
'The target URL to associate with this status'
# Examples:
optional
:description
,
type:
String
,
desc:
'A short description of the status'
# POST /projects/:id/statuses/:sha
optional
:name
,
type:
String
,
desc:
'A string label to differentiate this status from the status of other systems. Default: "default"'
optional
:context
,
type:
String
,
desc:
'A string label to differentiate this status from the status of other systems. Default: "default"'
end
post
':id/statuses/:sha'
do
post
':id/statuses/:sha'
do
authorize!
:create_commit_status
,
user_project
authorize!
:create_commit_status
,
user_project
required_attributes!
[
:state
]
attrs
=
attributes_for_keys
[
:target_url
,
:description
]
commit
=
@project
.
commit
(
params
[
:sha
])
commit
=
@project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
not_found!
'Commit'
unless
commit
...
@@ -68,7 +69,7 @@ module API
...
@@ -68,7 +69,7 @@ module API
status
=
GenericCommitStatus
.
running_or_pending
.
find_or_initialize_by
(
status
=
GenericCommitStatus
.
running_or_pending
.
find_or_initialize_by
(
project:
@project
,
pipeline:
pipeline
,
project:
@project
,
pipeline:
pipeline
,
user:
current_user
,
name:
name
,
ref:
ref
)
user:
current_user
,
name:
name
,
ref:
ref
)
status
.
attributes
=
attrs
status
.
attributes
=
declared
(
params
).
slice
(
:target_url
,
:description
)
begin
begin
case
params
[
:state
].
to_s
case
params
[
:state
].
to_s
...
...
spec/requests/api/commit_statuses_spec.rb
View file @
c7282f89
...
@@ -196,7 +196,7 @@ describe API::CommitStatuses, api: true do
...
@@ -196,7 +196,7 @@ describe API::CommitStatuses, api: true do
end
end
context
'reporter user'
do
context
'reporter user'
do
before
{
post
api
(
post_url
,
reporter
)
}
before
{
post
api
(
post_url
,
reporter
)
,
state:
'running'
}
it
'does not create commit status'
do
it
'does not create commit status'
do
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
...
@@ -204,7 +204,7 @@ describe API::CommitStatuses, api: true do
...
@@ -204,7 +204,7 @@ describe API::CommitStatuses, api: true do
end
end
context
'guest user'
do
context
'guest user'
do
before
{
post
api
(
post_url
,
guest
)
}
before
{
post
api
(
post_url
,
guest
)
,
state:
'running'
}
it
'does not create commit status'
do
it
'does not create commit status'
do
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
...
...
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