Commit ee956e0d authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'dz-integrated-error-tracking-setting-api' into 'master'

Integrated error tracking setting API

See merge request gitlab-org/gitlab!68260
parents 862d565d ef2a0398
......@@ -63,8 +63,15 @@ module Projects
# Make sure we're converting to symbols because
# * ActionController::Parameters#keys returns a list of strings
# * in specs we're using hashes with symbols as keys
update_keys = settings.keys.map(&:to_sym)
settings.keys.map(&:to_sym) == %i[enabled]
# Integrated error tracking works without Sentry integration,
# so we don't need to update all those values from error_tracking_params_for_update method.
# Instead we turn it on/off with partial update together with "enabled" attribute.
# But since its optional, we exclude it from the condition below.
update_keys.delete(:integrated)
update_keys == %i[enabled]
end
def error_tracking_params_for_partial_update(settings)
......
......@@ -34,7 +34,8 @@ Example response:
"active": true,
"project_name": "sample sentry project",
"sentry_external_url": "https://sentry.io/myawesomeproject/project",
"api_url": "https://sentry.io/api/0/projects/myawesomeproject/project"
"api_url": "https://sentry.io/api/0/projects/myawesomeproject/project",
"integrated": false
}
```
......@@ -46,10 +47,11 @@ The API allows you to enable or disable the Error Tracking settings for a projec
PATCH /projects/:id/error_tracking/settings
```
| Attribute | Type | Required | Description |
| --------- | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID or [URL-encoded path of the project](index.md#namespaced-path-encoding) owned by the authenticated user. |
| `active` | boolean | yes | Pass `true` to enable the already configured error tracking settings or `false` to disable it. |
| Attribute | Type | Required | Description |
| ------------ | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID or [URL-encoded path of the project](index.md#namespaced-path-encoding) owned by the authenticated user. |
| `active` | boolean | yes | Pass `true` to enable the already configured error tracking settings or `false` to disable it. |
| `integrated` | boolean | no | Pass `true` to enable the integrated error tracking backend. Available in [GitLab 14.2](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68260) and later. |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/error_tracking/settings?active=true"
......@@ -62,6 +64,7 @@ Example response:
"active": true,
"project_name": "sample sentry project",
"sentry_external_url": "https://sentry.io/myawesomeproject/project",
"api_url": "https://sentry.io/api/0/projects/myawesomeproject/project"
"api_url": "https://sentry.io/api/0/projects/myawesomeproject/project",
"integrated": false
}
```
......@@ -8,6 +8,7 @@ module API
expose :project_name
expose :sentry_external_url
expose :api_url
expose :integrated
end
end
end
......
......@@ -32,6 +32,7 @@ module API
end
params do
requires :active, type: Boolean, desc: 'Specifying whether to enable or disable error tracking settings', allow_blank: false
optional :integrated, type: Boolean, desc: 'Specifying whether to enable or disable integrated error tracking'
end
patch ':id/error_tracking/settings/' do
......@@ -45,6 +46,10 @@ module API
error_tracking_setting_attributes: { enabled: params[:active] }
}
unless params[:integrated].nil?
update_params[:error_tracking_setting_attributes][:integrated] = params[:integrated]
end
result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute
if result[:status] == :success
......
......@@ -17,7 +17,8 @@ RSpec.describe API::ErrorTracking do
'active' => setting.reload.enabled,
'project_name' => setting.project_name,
'sentry_external_url' => setting.sentry_external_url,
'api_url' => setting.api_url
'api_url' => setting.api_url,
'integrated' => setting.integrated
)
end
end
......@@ -79,6 +80,19 @@ RSpec.describe API::ErrorTracking do
.to eq('active is empty')
end
end
context 'with integrated param' do
let(:params) { { active: true, integrated: true } }
it 'updates the integrated flag' do
expect(setting.integrated).to be_falsey
make_request
expect(json_response).to include('integrated' => true)
expect(setting.reload.integrated).to be_truthy
end
end
end
context 'without a project setting' do
......
......@@ -262,6 +262,31 @@ RSpec.describe Projects::Operations::UpdateService do
expect(project.error_tracking_setting.previous_changes.keys)
.to contain_exactly('enabled')
end
context 'with integrated attribute' do
let(:params) do
{
error_tracking_setting_attributes: {
enabled: true,
integrated: true
}
}
end
it 'updates integrated attribute' do
expect { result }
.to change { project.reload.error_tracking_setting.integrated }
.from(false)
.to(true)
end
it 'only updates enabled and integrated attributes' do
result
expect(project.error_tracking_setting.previous_changes.keys)
.to contain_exactly('enabled', 'integrated')
end
end
end
context 'without setting' 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