Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
1dd712dd
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1dd712dd
编写于
3月 06, 2013
作者:
M
Matt Humphrey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
System hooks API.
上级
d03af842
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
177 addition
and
0 deletion
+177
-0
doc/api/system_hooks.md
doc/api/system_hooks.md
+47
-0
lib/api.rb
lib/api.rb
+1
-0
lib/api/system_hooks.rb
lib/api/system_hooks.rb
+60
-0
spec/requests/api/system_hooks_spec.rb
spec/requests/api/system_hooks_spec.rb
+69
-0
未找到文件。
doc/api/system_hooks.md
0 → 100644
浏览文件 @
1dd712dd
All methods require admin authorization.
## List system hooks
Get list of system hooks
```
GET /hooks
```
Will return hooks with status
`200 OK`
on success, or
`404 Not found`
on fail.
## Add new system hook hook
```
POST /hooks
```
Parameters:
+
`url`
(required) - The hook URL
Will return status
`201 Created`
on success, or
`404 Not found`
on fail.
## Test system hook
```
GET /hooks/:id
```
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
```
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.rb
浏览文件 @
1dd712dd
...
...
@@ -20,5 +20,6 @@ module Gitlab
mount
MergeRequests
mount
Notes
mount
Internal
mount
SystemHooks
end
end
lib/api/system_hooks.rb
0 → 100644
浏览文件 @
1dd712dd
module
Gitlab
# Hooks API
class
SystemHooks
<
Grape
::
API
before
{
authenticated_as_admin!
}
resource
:hooks
do
# Get the list of system hooks
#
# Example Request:
# GET /hooks
get
do
@hooks
=
SystemHook
.
all
present
@hooks
,
with:
Entities
::
Hook
end
# Create new system hook
#
# Parameters:
# url (required) - url for system hook
# Example Request
# POST /hooks
post
do
attrs
=
attributes_for_keys
[
:url
]
@hook
=
SystemHook
.
new
attrs
if
@hook
.
save
present
@hook
,
with:
Entities
::
Hook
else
not_found!
end
end
# Test a hook
#
# Example Request
# GET /hooks/:id
get
":id"
do
@hook
=
SystemHook
.
find
(
params
[
:id
])
data
=
{
event_name:
"project_create"
,
name:
"Ruby"
,
path:
"ruby"
,
project_id:
1
,
owner_name:
"Someone"
,
owner_email:
"example@gitlabhq.com"
}
@hook
.
execute
(
data
)
data
end
# Delete a hook
#
# Example Request:
# DELETE /hooks/:id
delete
":id"
do
@hook
=
SystemHook
.
find
(
params
[
:id
])
@hook
.
destroy
end
end
end
end
\ No newline at end of file
spec/requests/api/system_hooks_spec.rb
0 → 100644
浏览文件 @
1dd712dd
require
'spec_helper'
describe
Gitlab
::
API
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let!
(
:hook
)
{
create
(
:system_hook
,
url:
"http://example.com"
)
}
before
{
stub_request
(
:post
,
hook
.
url
)
}
describe
"GET /hooks"
do
context
"when not an admin"
do
it
"should return forbidden error"
do
get
api
(
"/hooks"
,
user
)
response
.
status
.
should
==
403
end
end
context
"when authenticated as admin"
do
it
"should return an array of hooks"
do
get
api
(
"/hooks"
,
admin
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'url'
].
should
==
hook
.
url
end
end
end
describe
"POST /hooks"
do
it
"should create new hook"
do
expect
{
post
api
(
"/hooks"
,
admin
),
url:
'http://example.com'
}.
to
change
{
SystemHook
.
count
}.
by
(
1
)
end
it
"should respond with 404 on failure"
do
post
api
(
"/hooks"
,
admin
)
response
.
status
.
should
==
404
end
it
"should not create new hook without url"
do
expect
{
post
api
(
"/hooks"
,
admin
)
}.
to_not
change
{
SystemHook
.
count
}
end
end
describe
"GET /hooks/:id"
do
it
"should return hook by id"
do
get
api
(
"/hooks/
#{
hook
.
id
}
"
,
admin
)
response
.
status
.
should
==
200
json_response
[
'event_name'
].
should
==
'project_create'
end
it
"should return 404 on failure"
do
get
api
(
"/hooks/404"
,
admin
)
response
.
status
.
should
==
404
end
end
describe
"DELETE /hooks/:id"
do
it
"should delete a hook"
do
expect
{
delete
api
(
"/hooks/
#{
hook
.
id
}
"
,
admin
)
}.
to
change
{
SystemHook
.
count
}.
by
(
-
1
)
end
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录