BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
a29c883b
Commit
a29c883b
authored
Mar 10, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3170 from Asquera/api/system_hooks_adjustments
API: system hook request functions and documentation updated
parents
269a9859
562de2a4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
10 deletions
+34
-10
system_hooks.md
doc/api/system_hooks.md
+7
-6
system_hooks.rb
lib/api/system_hooks.rb
+12
-2
system_hooks_spec.rb
spec/requests/api/system_hooks_spec.rb
+15
-2
No files found.
doc/api/system_hooks.md
View file @
a29c883b
...
...
@@ -8,7 +8,10 @@ Get list of system hooks
GET /hooks
```
Will return hooks with status
`200 OK`
on success, or
`404 Not found`
on fail.
Parameters:
+
**none**
## Add new system hook hook
...
...
@@ -20,7 +23,6 @@ Parameters:
+
`url`
(required) - The hook URL
Will return status
`201 Created`
on success, or
`404 Not found`
on fail.
## Test system hook
...
...
@@ -32,10 +34,12 @@ Parameters:
+
`id`
(required) - The ID of hook
Will return hook with status
`200 OK`
on success, or
`404 Not found`
on fail.
## Delete system hook
Deletes a system hook. This is an idempotent API function and returns
`200 Ok`
even if the hook
is not available. If the hook is deleted it is also returned as JSON.
```
DELETE /hooks/:id
```
...
...
@@ -43,5 +47,3 @@ DELETE /hooks/:id
Parameters:
+
`id`
(required) - The ID of hook
Will return status
`200 OK`
on success, or
`404 Not found`
on fail.
\ No newline at end of file
lib/api/system_hooks.rb
View file @
a29c883b
module
Gitlab
# Hooks API
class
SystemHooks
<
Grape
::
API
before
{
authenticated_as_admin!
}
before
{
authenticate!
authenticated_as_admin!
}
resource
:hooks
do
# Get the list of system hooks
...
...
@@ -21,6 +24,7 @@ module Gitlab
# POST /hooks
post
do
attrs
=
attributes_for_keys
[
:url
]
required_attributes!
[
:url
]
@hook
=
SystemHook
.
new
attrs
if
@hook
.
save
present
@hook
,
with:
Entities
::
Hook
...
...
@@ -47,13 +51,19 @@ module Gitlab
data
end
# Delete a hook
# Delete a hook
. This is an idempotent function.
#
# Parameters:
# id (required) - ID of the hook
# Example Request:
# DELETE /hooks/:id
delete
":id"
do
begin
@hook
=
SystemHook
.
find
(
params
[
:id
])
@hook
.
destroy
rescue
# SystemHook raises an Error if no hook with id found
end
end
end
end
...
...
spec/requests/api/system_hooks_spec.rb
View file @
a29c883b
...
...
@@ -10,6 +10,13 @@ describe Gitlab::API do
before
{
stub_request
(
:post
,
hook
.
url
)
}
describe
"GET /hooks"
do
context
"when no user"
do
it
"should return authentication error"
do
get
api
(
"/hooks"
)
response
.
status
.
should
==
401
end
end
context
"when not an admin"
do
it
"should return forbidden error"
do
get
api
(
"/hooks"
,
user
)
...
...
@@ -34,9 +41,9 @@ describe Gitlab::API do
}.
to
change
{
SystemHook
.
count
}.
by
(
1
)
end
it
"should respond with 40
4 on failure
"
do
it
"should respond with 40
0 if url not given
"
do
post
api
(
"/hooks"
,
admin
)
response
.
status
.
should
==
40
4
response
.
status
.
should
==
40
0
end
it
"should not create new hook without url"
do
...
...
@@ -65,5 +72,10 @@ describe Gitlab::API do
delete
api
(
"/hooks/
#{
hook
.
id
}
"
,
admin
)
}.
to
change
{
SystemHook
.
count
}.
by
(
-
1
)
end
it
"should return success if hook id not found"
do
delete
api
(
"/hooks/12345"
,
admin
)
response
.
status
.
should
==
200
end
end
end
\ No newline at end of file
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