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

160 lines
3.5 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
class Projects::ErrorTrackingController < Projects::ApplicationController
before_action :authorize_read_sentry_issue!
2019-12-26 22:10:19 +05:30
before_action :set_issue_id, only: [:details, :stack_trace]
2019-02-15 15:39:39 +05:30
POLLING_INTERVAL = 10_000
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
render_issue_detail_json
end
end
end
def stack_trace
respond_to do |format|
format.json do
render_issue_stack_trace_json
end
end
end
2019-03-02 22:35:43 +05:30
def list_projects
respond_to do |format|
format.json do
render_project_list_json
end
end
end
2019-02-15 15:39:39 +05:30
private
def render_index_json
2020-01-01 13:55:28 +05:30
service = ErrorTracking::ListIssuesService.new(
project,
current_user,
list_issues_params
)
2019-02-15 15:39:39 +05:30
result = service.execute
2019-12-26 22:10:19 +05:30
return if handle_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
service = ErrorTracking::IssueDetailsService.new(project, current_user, issue_details_params)
result = service.execute
return if handle_errors(result)
render json: {
error: serialize_detailed_error(result[:issue])
}
end
def render_issue_stack_trace_json
service = ErrorTracking::IssueLatestEventService.new(project, current_user, issue_details_params)
result = service.execute
return if handle_errors(result)
2020-01-01 13:55:28 +05:30
result_with_syntax_highlight = Gitlab::ErrorTracking::StackTraceHighlightDecorator.decorate(result[:latest_event])
2019-12-26 22:10:19 +05:30
render json: {
2020-01-01 13:55:28 +05:30
error: serialize_error_event(result_with_syntax_highlight)
2019-12-26 22:10:19 +05:30
}
end
2019-03-02 22:35:43 +05:30
def render_project_list_json
service = ErrorTracking::ListProjectsService.new(
project,
current_user,
list_projects_params
)
result = service.execute
if result[:status] == :success
render json: {
projects: serialize_projects(result[:projects])
}
else
return render(
status: result[:http_status] || :bad_request,
json: {
message: result[:message]
}
)
end
end
2019-12-26 22:10:19 +05:30
def handle_errors(result)
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
params.permit(:search_term, :sort, :cursor)
end
2019-03-02 22:35:43 +05:30
def list_projects_params
params.require(:error_tracking_setting).permit([:api_host, :token])
end
2019-12-26 22:10:19 +05:30
def issue_details_params
params.permit(:issue_id)
end
def set_issue_id
@issue_id = issue_details_params[:issue_id]
end
2019-02-15 15:39:39 +05:30
def set_polling_interval
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
end
def serialize_errors(errors)
ErrorTracking::ErrorSerializer
.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)
ErrorTracking::DetailedErrorSerializer
.new(project: project, user: current_user)
.represent(error)
end
def serialize_error_event(event)
ErrorTracking::ErrorEventSerializer
.new(project: project, user: current_user)
.represent(event)
end
2019-03-02 22:35:43 +05:30
def serialize_projects(projects)
ErrorTracking::ProjectSerializer
.new(project: project, user: current_user)
.represent(projects)
end
2019-02-15 15:39:39 +05:30
end