debian-mirror-gitlab/app/controllers/projects/error_tracking_controller.rb

109 lines
2.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2020-03-13 15:44:24 +05:30
class Projects::ErrorTrackingController < Projects::ErrorTracking::BaseController
respond_to :json
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
before_action :authorize_read_sentry_issue!
before_action :set_issue_id, only: :details
2019-02-15 15:39:39 +05:30
2022-05-07 20:08:51 +05:30
before_action only: [:index] do
push_frontend_feature_flag(:integrated_error_tracking, project)
end
2019-02-15 15:39:39 +05:30
def index
respond_to do |format|
format.html
format.json do
set_polling_interval
render_index_json
end
end
end
2019-12-26 22:10:19 +05:30
def details
respond_to do |format|
format.html
format.json do
2020-03-13 15:44:24 +05:30
set_polling_interval
2019-12-26 22:10:19 +05:30
render_issue_detail_json
end
end
end
2020-03-13 15:44:24 +05:30
def update
2021-10-27 15:23:28 +05:30
service = ::ErrorTracking::IssueUpdateService.new(project, current_user, issue_update_params)
2020-03-13 15:44:24 +05:30
result = service.execute
2019-12-26 22:10:19 +05:30
2020-03-13 15:44:24 +05:30
return if render_errors(result)
render json: {
result: result
}
2019-03-02 22:35:43 +05:30
end
2019-02-15 15:39:39 +05:30
private
def render_index_json
2021-10-27 15:23:28 +05:30
service = ::ErrorTracking::ListIssuesService.new(
2020-01-01 13:55:28 +05:30
project,
current_user,
list_issues_params
)
2019-02-15 15:39:39 +05:30
result = service.execute
2020-03-13 15:44:24 +05:30
return if render_errors(result)
2019-02-15 15:39:39 +05:30
render json: {
errors: serialize_errors(result[:issues]),
2020-01-01 13:55:28 +05:30
pagination: result[:pagination],
2019-02-15 15:39:39 +05:30
external_url: service.external_url
}
end
2019-12-26 22:10:19 +05:30
def render_issue_detail_json
2021-10-27 15:23:28 +05:30
service = ::ErrorTracking::IssueDetailsService.new(project, current_user, issue_details_params)
2019-12-26 22:10:19 +05:30
result = service.execute
2020-03-13 15:44:24 +05:30
return if render_errors(result)
2019-12-26 22:10:19 +05:30
render json: {
error: serialize_detailed_error(result[:issue])
}
end
2020-03-13 15:44:24 +05:30
def render_errors(result)
2019-12-26 22:10:19 +05:30
unless result[:status] == :success
render json: { message: result[:message] },
status: result[:http_status] || :bad_request
end
end
2020-01-01 13:55:28 +05:30
def list_issues_params
2022-05-07 20:08:51 +05:30
params.permit(:search_term, :sort, :cursor, :issue_status).merge(tracking_event: :error_tracking_view_list)
2020-01-01 13:55:28 +05:30
end
2020-03-13 15:44:24 +05:30
def issue_update_params
params.permit(:issue_id, :status)
2019-03-02 22:35:43 +05:30
end
2019-12-26 22:10:19 +05:30
def issue_details_params
2022-05-07 20:08:51 +05:30
params.permit(:issue_id).merge(tracking_event: :error_tracking_view_details)
2019-12-26 22:10:19 +05:30
end
def set_issue_id
@issue_id = issue_details_params[:issue_id]
end
2019-02-15 15:39:39 +05:30
def serialize_errors(errors)
2021-10-27 15:23:28 +05:30
::ErrorTracking::ErrorSerializer
2019-02-15 15:39:39 +05:30
.new(project: project, user: current_user)
.represent(errors)
end
2019-03-02 22:35:43 +05:30
2019-12-26 22:10:19 +05:30
def serialize_detailed_error(error)
2021-10-27 15:23:28 +05:30
::ErrorTracking::DetailedErrorSerializer
2019-12-26 22:10:19 +05:30
.new(project: project, user: current_user)
.represent(error)
end
2019-02-15 15:39:39 +05:30
end