2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ErrorTracking
|
2019-12-26 22:10:19 +05:30
|
|
|
class ListIssuesService < ErrorTracking::BaseService
|
2019-02-15 15:39:39 +05:30
|
|
|
DEFAULT_ISSUE_STATUS = 'unresolved'
|
|
|
|
DEFAULT_LIMIT = 20
|
2020-01-01 13:55:28 +05:30
|
|
|
DEFAULT_SORT = 'last_seen'
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
# Sentry client supports 'muted' and 'assigned' but GitLab does not
|
|
|
|
ISSUE_STATUS_VALUES = %w[
|
|
|
|
resolved
|
|
|
|
unresolved
|
|
|
|
ignored
|
|
|
|
].freeze
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def external_url
|
|
|
|
project_error_tracking_setting&.sentry_external_url
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def perform
|
|
|
|
return invalid_status_error unless valid_status?
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
sentry_opts = {
|
2020-01-01 13:55:28 +05:30
|
|
|
issue_status: issue_status,
|
|
|
|
limit: limit,
|
|
|
|
search_term: params[:search_term].presence,
|
|
|
|
sort: sort,
|
|
|
|
cursor: params[:cursor].presence
|
2021-10-27 15:23:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
response = list_issues(sentry_opts)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
compose_response(response)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def parse_response(response)
|
2020-01-01 13:55:28 +05:30
|
|
|
response.slice(:issues, :pagination)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def invalid_status_error
|
|
|
|
error('Bad Request: Invalid issue_status', http_status_for(:bad_Request))
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_status?
|
|
|
|
ISSUE_STATUS_VALUES.include?(issue_status)
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def issue_status
|
|
|
|
params[:issue_status] || DEFAULT_ISSUE_STATUS
|
|
|
|
end
|
|
|
|
|
|
|
|
def limit
|
|
|
|
params[:limit] || DEFAULT_LIMIT
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
def sort
|
|
|
|
params[:sort] || DEFAULT_SORT
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
def list_issues(opts)
|
|
|
|
# There are 2 types of the data source for the error tracking feature:
|
|
|
|
#
|
|
|
|
# * When integrated error tracking is enabled, we use the application database
|
|
|
|
# to read and save error tracking data.
|
|
|
|
#
|
|
|
|
# * When integrated error tracking is disabled we call
|
|
|
|
# project_error_tracking_setting method which works with Sentry API.
|
|
|
|
#
|
|
|
|
# Issue https://gitlab.com/gitlab-org/gitlab/-/issues/329596
|
|
|
|
#
|
|
|
|
if project_error_tracking_setting.integrated_client?
|
|
|
|
# We are going to support more options in the future.
|
|
|
|
# For now we implement the bare minimum for rendering the list in UI.
|
|
|
|
filter_opts = {
|
2021-11-11 11:23:49 +05:30
|
|
|
status: opts[:issue_status],
|
|
|
|
sort: opts[:sort],
|
|
|
|
limit: opts[:limit]
|
2021-10-27 15:23:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
errors = ErrorTracking::ErrorsFinder.new(current_user, project, filter_opts).execute
|
|
|
|
|
|
|
|
# We use the same response format as project_error_tracking_setting
|
|
|
|
# method below for compatibility with existing code.
|
|
|
|
{
|
|
|
|
issues: errors.map(&:to_sentry_error),
|
|
|
|
pagination: {}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
project_error_tracking_setting.list_sentry_issues(**opts)
|
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|