Commit ac208068 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'feature/system-hook-get-api' into 'master'

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

See merge request gitlab-org/gitlab!81595
Changelog: changed
parents cadd26b8 a99f32d0
......@@ -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
......
{
"type": "object",
"required": [
"id",
"url",
"created_at",
"push_events",
"tag_push_events",
"merge_requests_events",
"repository_update_events",
"enable_ssl_verification"
],
"properties": {
"id": { "type": "integer" },
"url": { "type": "string" },
"created_at": { "type": "string" },
"push_events": { "type": "boolean" },
"tag_push_events": { "type": "boolean" },
"merge_requests_events": { "type": "boolean" },
"repository_update_events": { "type": "boolean" },
"enable_ssl_verification": { "type": "boolean" }
},
"additionalProperties": false
}
{
"type": "array",
"items": {
"type": "object",
"properties" : {
"$ref": "./system_hook.json"
}
}
}
......@@ -36,12 +36,57 @@ RSpec.describe API::SystemHooks do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(response).to match_response_schema('public_api/v4/system_hooks')
expect(json_response.first).not_to have_key("token")
expect(json_response.first['url']).to eq(hook.url)
expect(json_response.first['push_events']).to be false
expect(json_response.first['tag_push_events']).to be false
expect(json_response.first['merge_requests_events']).to be false
expect(json_response.first['repository_update_events']).to be true
expect(json_response.first['enable_ssl_verification']).to be true
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(response).to match_response_schema('public_api/v4/system_hook')
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
......@@ -77,6 +122,7 @@ RSpec.describe API::SystemHooks do
post api('/hooks', admin), params: { url: 'http://mep.mep' }
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/system_hook')
expect(json_response['enable_ssl_verification']).to be true
expect(json_response['push_events']).to be false
expect(json_response['tag_push_events']).to be false
......@@ -98,6 +144,7 @@ RSpec.describe API::SystemHooks do
}
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/system_hook')
expect(json_response['enable_ssl_verification']).to be false
expect(json_response['push_events']).to be true
expect(json_response['tag_push_events']).to be true
......
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