Commit 1ddb075b authored by raju249's avatar raju249

Use new endpoint, use generic name , remove sentry word in docs

parent 4be09441
......@@ -29,7 +29,7 @@ The following API resources are available in the project context:
| [Deployments](deployments.md) | `/projects/:id/deployments` |
| [Discussions](discussions.md) (threaded comments) | `/projects/:id/issues/.../discussions`, `/projects/:id/snippets/.../discussions`, `/projects/:id/merge_requests/.../discussions`, `/projects/:id/commits/.../discussions` (also available for groups) |
| [Environments](environments.md) | `/projects/:id/environments` |
| [Error Tracking](sentry_project_settings.md) | `/projects/:id/error_tracking/sentry_project_settings` |
| [Error Tracking](error_tracking.md) | `/projects/:id/error_tracking/settings` |
| [Events](events.md) | `/projects/:id/events` (also available for users and standalone) |
| [Issues](issues.md) | `/projects/:id/issues` (also available for groups and standalone) |
| [Issues Statistics](issues_statistics.md) | `/projects/:id/issues_statistics` (also available for groups and standalone) |
......
# Sentry Project Settings API
# Error Tracking Settings API
## Sentry Error Tracking Project Settings
> [Introduced](https://gitlab.com/gitlab-org/gitlab/issues/34940) in GitLab 12.7.
## Error Tracking Project Settings
The Sentry Project Settings API allows you to retrieve Sentry Error Tracking Settings for a Project. Only for project maintainers.
### Retrieve Sentry Error Tracking Settings
### Retrieve Error Tracking Settings
```
GET /projects/:id/error_tracking/sentry_project_settings
GET /projects/:id/error_tracking/settings
```
| Attribute | Type | Required | Description |
......@@ -15,7 +17,7 @@ GET /projects/:id/error_tracking/sentry_project_settings
| `id` | integer | yes | The ID of the project owned by the authenticated user |
```bash
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/1/error_tracking/sentry_project_settings
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/1/error_tracking/settings
```
Example response:
......@@ -23,6 +25,7 @@ Example response:
```json
{
"project_name": "sample sentry project",
"sentry_external_url": "https://sentry.io/myawesomeproject/project"
"sentry_external_url": "https://sentry.io/myawesomeproject/project",
"api_url": "https://sentry.io/api/0/projects/myawesomeproject/project"
}
```
......@@ -166,11 +166,6 @@ module API
end
end
class SentryProjectErrorTrackingSettings < Grape::Entity
expose :project_name
expose :sentry_external_url
end
class RemoteMirror < Grape::Entity
expose :id
expose :enabled
......
# frozen_string_literal: true
module API
module Entities
module ErrorTracking
class ProjectSetting < Grape::Entity
expose :project_name
expose :sentry_external_url
expose :api_url
end
end
end
end
\ No newline at end of file
......@@ -9,18 +9,18 @@ module API
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get sentry error tracking settings for the project' do
success Entities::SentryProjectErrorTrackingSettings
desc 'Get error tracking settings for the project' do
success Entities::ErrorTracking::ProjectSetting
end
get ':id/error_tracking/sentry_project_settings' do
authorize! :read_sentry_issue, user_project
get ':id/error_tracking/settings' do
authorize! :admin_operations, user_project
setting = user_project.error_tracking_setting
not_found!('Error Tracking Setting') unless setting
present setting, with: Entities::SentryProjectErrorTrackingSettings
present setting, with: Entities::ErrorTracking::ProjectSetting
end
end
end
......
......@@ -3,50 +3,59 @@
require 'spec_helper'
describe API::ErrorTracking do
describe "GET sentry project settings" do
let(:unauthorized_message) { "401 Unauthorized" }
let(:settings_not_found_message) { "404 Error Tracking Setting Not Found" }
let(:random_user) { create(:user) }
let(:project_error_tracking_setting) { create(:project_error_tracking_setting) }
let(:project) do
create(:project, :repository)
describe "GET /projects/:id/error_tracking/settings" do
let(:user) { create(:user) }
let(:setting) { create(:project_error_tracking_setting) }
let(:project) { setting.project }
def make_request
get api("/projects/#{project.id}/error_tracking/settings", user)
end
let(:project_with_settings) do
create(:project, :repository, error_tracking_setting: project_error_tracking_setting)
context 'when authenticated as maintainer' do
before do
project.add_maintainer(user)
end
context 'when project has no settings' do
it 'returns 404' do
get api("/projects/#{project.id}/error_tracking/sentry_project_settings", project.creator)
it 'returns project settings' do
make_request
expect(response).to have_gitlab_http_status(404)
expect(json_response["message"]).to eq(settings_not_found_message)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq(
'project_name' => setting.project_name,
'sentry_external_url' => setting.sentry_external_url,
'api_url' => setting.api_url
)
end
end
context 'when user has permission to view settings' do
it 'returns 200' do
get api("/projects/#{project_with_settings.id}/error_tracking/sentry_project_settings", project_with_settings.creator)
context 'when authenticated as reporter' do
before do
project.add_reporter(user)
end
it 'returns 403' do
make_request
expect(response).to have_gitlab_http_status(200)
expect(json_response["project_name"]).to eq(project_error_tracking_setting.project_name)
expect(json_response["sentry_external_url"]).to eq(project_error_tracking_setting.sentry_external_url)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'When user does not own the project' do
context 'when authenticated as non-member' do
it 'returns 404' do
get api("/projects/#{project.id}/error_tracking/sentry_project_settings", random_user)
expect(response).to have_gitlab_http_status(404)
make_request
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'When unauthenticated' do
it 'return 401' do
get api("/projects/#{project.id}/error_tracking/sentry_project_settings")
expect(response).to have_gitlab_http_status(401)
expect(json_response["message"]).to eq(unauthorized_message)
context 'when unauthenticated' do
let(:user) { nil }
it 'returns 401' do
make_request
expect(response).to have_gitlab_http_status(:unauthorized)
end
end
end
......
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