Commit 5edbe24d authored by Andy Soiron's avatar Andy Soiron Committed by Stan Hu

New API endpoint GET /projects/:id/services

This commit adds a new API endpint
that returns a list of all services available
on a project
parent 15a86e9d
---
title: New API endpoint GET /projects/:id/services
merge_request: 21330
author:
type: added
......@@ -2,6 +2,59 @@
>**Note:** This API requires an access token with Maintainer or Owner permissions
## List all active services
> [Introduced](https://gitlab.com/gitlab-org/gitlab/merge_requests/21330) in GitLab 12.7.
Get a list of all active project services.
```
GET /projects/:id/services
```
Example response:
```json
[
{
"id": 75,
"title": "Jenkins CI",
"created_at": "2019-11-20T11:20:25.297Z",
"updated_at": "2019-11-20T12:24:37.498Z",
"active": true,
"commit_events": true,
"push_events": true,
"issues_events": true,
"confidential_issues_events": true,
"merge_requests_events": true,
"tag_push_events": false,
"note_events": true,
"confidential_note_events": true,
"pipeline_events": true,
"wiki_page_events": true,
"job_events": true
}
{
"id": 76,
"title": "Alerts endpoint",
"created_at": "2019-11-20T11:20:25.297Z",
"updated_at": "2019-11-20T12:24:37.498Z",
"active": true,
"commit_events": true,
"push_events": true,
"issues_events": true,
"confidential_issues_events": true,
"merge_requests_events": true,
"tag_push_events": true,
"note_events": true,
"confidential_note_events": true,
"pipeline_events": true,
"wiki_page_events": true,
"job_events": true
}
]
```
## Asana
Asana - Teamwork without email
......
......@@ -1109,12 +1109,15 @@ module API
end
end
class ProjectService < Grape::Entity
class ProjectServiceBasic < Grape::Entity
expose :id, :title, :created_at, :updated_at, :active
expose :commit_events, :push_events, :issues_events, :confidential_issues_events
expose :merge_requests_events, :tag_push_events, :note_events
expose :confidential_note_events, :pipeline_events, :wiki_page_events
expose :job_events
end
class ProjectService < ProjectServiceBasic
# Expose serialized properties
expose :properties do |service, options|
# TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
......
......@@ -66,6 +66,15 @@ module API
end
end
desc 'Get all active project services' do
success Entities::ProjectServiceBasic
end
get ":id/services" do
services = user_project.services.active
present services, with: Entities::ProjectServiceBasic
end
SERVICES.each do |service_slug, settings|
desc "Set #{service_slug} service for project"
params do
......
{
"type": "object",
"properties": {
"id": { "type": "integer" },
"title": { "type": "string" },
"created_at": { "type": "date-time" },
"updated_at": { "type": "date-time" },
"active": { "type": "boolean" },
"commit_events": { "type": "boolean" },
"push_events": { "type": "boolean" },
"issues_events": { "type": "boolean" },
"confidential_issues_events": { "type": "boolean" },
"merge_requests_events": { "type": "boolean" },
"tag_push_events": { "type": "boolean" },
"note_events": { "type": "boolean" },
"confidential_note_events": { "type": "boolean" },
"pipeline_events": { "type": "boolean" },
"wiki_page_events": { "type": "boolean" },
"job_events": { "type": "boolean" }
},
"additionalProperties": false
}
{
"type": "array",
"items": { "$ref": "service.json" }
}
......@@ -10,6 +10,37 @@ describe API::Services do
create(:project, creator_id: user.id, namespace: user.namespace)
end
describe "GET /projects/:id/services" do
it 'returns authentication error when unauthenticated' do
get api("/projects/#{project.id}/services")
expect(response).to have_gitlab_http_status(401)
end
it "returns error when authenticated but user is not a project owner" do
project.add_developer(user2)
get api("/projects/#{project.id}/services", user2)
expect(response).to have_gitlab_http_status(403)
end
context 'project with services' do
let!(:active_service) { create(:emails_on_push_service, project: project, active: true) }
let!(:service) { create(:custom_issue_tracker_service, project: project, active: false) }
it "returns a list of all active services" do
get api("/projects/#{project.id}/services", user)
aggregate_failures 'expect successful response with all active services' do
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array
expect(json_response.count).to eq(1)
expect(response).to match_response_schema('public_api/v4/services')
end
end
end
end
Service.available_services_names.each do |service|
describe "PUT /projects/:id/services/#{service.dasherize}" do
include_context service
......
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