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
|
|
|
|
|
|
|
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
|
|
|
|
service = ErrorTracking::IssueUpdateService.new(project, current_user, issue_update_params)
|
|
|
|
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
|
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
|
|
|
|
|
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
|
|
|
|
service = ErrorTracking::IssueDetailsService.new(project, current_user, issue_details_params)
|
|
|
|
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
|
2020-03-13 15:44:24 +05:30
|
|
|
params.permit(:search_term, :sort, :cursor, :issue_status)
|
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
|
|
|
|
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 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
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|