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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
83556144
Commit
83556144
authored
Feb 25, 2022
by
Timo Furrer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement `/hooks/:id` GET API for system hooks
Closes:
https://gitlab.com/gitlab-org/gitlab/-/issues/353819
parent
0a501f74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
+91
-0
doc/api/system_hooks.md
doc/api/system_hooks.md
+37
-0
lib/api/system_hooks.rb
lib/api/system_hooks.rb
+12
-0
spec/requests/api/system_hooks_spec.rb
spec/requests/api/system_hooks_spec.rb
+42
-0
No files found.
doc/api/system_hooks.md
View file @
83556144
...
@@ -46,6 +46,43 @@ Example response:
...
@@ -46,6 +46,43 @@ Example response:
]
]
```
```
## Get system hook
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81595) in GitLab 14.9.
Get a system hook by its ID.
```
plaintext
GET /hooks/:id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer | yes | The ID of the hook |
Example request:
```
shell
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
"https://gitlab.example.com/api/v4/hooks/1"
```
Example response:
```
json
[
{
"id"
:
1
,
"url"
:
"https://gitlab.example.com/hook"
,
"created_at"
:
"2016-10-31T12:32:15.192Z"
,
"push_events"
:
true
,
"tag_push_events"
:
false
,
"merge_requests_events"
:
true
,
"repository_update_events"
:
true
,
"enable_ssl_verification"
:
true
}
]
```
## Add new system hook
## Add new system hook
Add a new system hook.
Add a new system hook.
...
...
lib/api/system_hooks.rb
View file @
83556144
...
@@ -22,6 +22,18 @@ module API
...
@@ -22,6 +22,18 @@ module API
present
paginate
(
SystemHook
.
all
),
with:
Entities
::
Hook
present
paginate
(
SystemHook
.
all
),
with:
Entities
::
Hook
end
end
desc
'Get a hook'
do
success
Entities
::
Hook
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the system hook'
end
get
":id"
do
hook
=
SystemHook
.
find
(
params
[
:id
])
present
hook
,
with:
Entities
::
Hook
end
desc
'Create a new system hook'
do
desc
'Create a new system hook'
do
success
Entities
::
Hook
success
Entities
::
Hook
end
end
...
...
spec/requests/api/system_hooks_spec.rb
View file @
83556144
...
@@ -48,6 +48,48 @@ RSpec.describe API::SystemHooks do
...
@@ -48,6 +48,48 @@ RSpec.describe API::SystemHooks do
end
end
end
end
describe
"GET /hooks/:id"
do
context
"when no user"
do
it
"returns authentication error"
do
get
api
(
"/hooks/
#{
hook
.
id
}
"
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
context
"when not an admin"
do
it
"returns forbidden error"
do
get
api
(
"/hooks/
#{
hook
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
context
"when authenticated as admin"
do
it
"gets a hook"
,
:aggregate_failures
do
get
api
(
"/hooks/
#{
hook
.
id
}
"
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
match
(
'id'
=>
be
(
hook
.
id
),
'url'
=>
eq
(
hook
.
url
),
'created_at'
=>
eq
(
hook
.
created_at
.
iso8601
(
3
)),
'push_events'
=>
be
(
hook
.
push_events
),
'tag_push_events'
=>
be
(
hook
.
tag_push_events
),
'merge_requests_events'
=>
be
(
hook
.
merge_requests_events
),
'repository_update_events'
=>
be
(
hook
.
repository_update_events
),
'enable_ssl_verification'
=>
be
(
hook
.
enable_ssl_verification
)
)
end
it
'returns 404 if the system hook does not exist'
do
get
api
(
"/hooks/
#{
non_existing_record_id
}
"
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
describe
"POST /hooks"
do
describe
"POST /hooks"
do
it
"creates new hook"
do
it
"creates new hook"
do
expect
do
expect
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