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: ...@@ -29,7 +29,7 @@ The following API resources are available in the project context:
| [Deployments](deployments.md) | `/projects/:id/deployments` | | [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) | | [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` | | [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) | | [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](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) | | [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. 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 | | Attribute | Type | Required | Description |
...@@ -15,7 +17,7 @@ GET /projects/:id/error_tracking/sentry_project_settings ...@@ -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 | | `id` | integer | yes | The ID of the project owned by the authenticated user |
```bash ```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: Example response:
...@@ -23,6 +25,7 @@ Example response: ...@@ -23,6 +25,7 @@ Example response:
```json ```json
{ {
"project_name": "sample sentry project", "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 ...@@ -166,11 +166,6 @@ module API
end end
end end
class SentryProjectErrorTrackingSettings < Grape::Entity
expose :project_name
expose :sentry_external_url
end
class RemoteMirror < Grape::Entity class RemoteMirror < Grape::Entity
expose :id expose :id
expose :enabled 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 ...@@ -9,18 +9,18 @@ module API
end end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get sentry error tracking settings for the project' do desc 'Get error tracking settings for the project' do
success Entities::SentryProjectErrorTrackingSettings success Entities::ErrorTracking::ProjectSetting
end end
get ':id/error_tracking/sentry_project_settings' do get ':id/error_tracking/settings' do
authorize! :read_sentry_issue, user_project authorize! :admin_operations, user_project
setting = user_project.error_tracking_setting setting = user_project.error_tracking_setting
not_found!('Error Tracking Setting') unless setting not_found!('Error Tracking Setting') unless setting
present setting, with: Entities::SentryProjectErrorTrackingSettings present setting, with: Entities::ErrorTracking::ProjectSetting
end end
end end
end end
......
...@@ -3,50 +3,59 @@ ...@@ -3,50 +3,59 @@
require 'spec_helper' require 'spec_helper'
describe API::ErrorTracking do describe API::ErrorTracking do
describe "GET sentry project settings" do describe "GET /projects/:id/error_tracking/settings" do
let(:unauthorized_message) { "401 Unauthorized" } let(:user) { create(:user) }
let(:settings_not_found_message) { "404 Error Tracking Setting Not Found" } let(:setting) { create(:project_error_tracking_setting) }
let(:random_user) { create(:user) } let(:project) { setting.project }
let(:project_error_tracking_setting) { create(:project_error_tracking_setting) }
let(:project) do def make_request
create(:project, :repository) get api("/projects/#{project.id}/error_tracking/settings", user)
end end
let(:project_with_settings) do context 'when authenticated as maintainer' do
create(:project, :repository, error_tracking_setting: project_error_tracking_setting) before do
project.add_maintainer(user)
end end
context 'when project has no settings' do it 'returns project settings' do
it 'returns 404' do make_request
get api("/projects/#{project.id}/error_tracking/sentry_project_settings", project.creator)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:ok)
expect(json_response["message"]).to eq(settings_not_found_message) expect(json_response).to eq(
'project_name' => setting.project_name,
'sentry_external_url' => setting.sentry_external_url,
'api_url' => setting.api_url
)
end end
end end
context 'when user has permission to view settings' do context 'when authenticated as reporter' do
it 'returns 200' do before do
get api("/projects/#{project_with_settings.id}/error_tracking/sentry_project_settings", project_with_settings.creator) project.add_reporter(user)
end
it 'returns 403' do
make_request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:forbidden)
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)
end end
end end
context 'When user does not own the project' do context 'when authenticated as non-member' do
it 'returns 404' do it 'returns 404' do
get api("/projects/#{project.id}/error_tracking/sentry_project_settings", random_user) make_request
expect(response).to have_gitlab_http_status(404)
expect(response).to have_gitlab_http_status(:not_found)
end end
end end
context 'When unauthenticated' do context 'when unauthenticated' do
it 'return 401' do let(:user) { nil }
get api("/projects/#{project.id}/error_tracking/sentry_project_settings")
expect(response).to have_gitlab_http_status(401) it 'returns 401' do
expect(json_response["message"]).to eq(unauthorized_message) make_request
expect(response).to have_gitlab_http_status(:unauthorized)
end end
end 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