Commit 83556144 authored by Timo Furrer's avatar Timo Furrer

Implement `/hooks/:id` GET API for system hooks

Closes: https://gitlab.com/gitlab-org/gitlab/-/issues/353819
parent 0a501f74
......@@ -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 a new system hook.
......
......@@ -22,6 +22,18 @@ module API
present paginate(SystemHook.all), with: Entities::Hook
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
success Entities::Hook
end
......
......@@ -48,6 +48,48 @@ RSpec.describe API::SystemHooks do
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
it "creates new hook" do
expect do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment