diff options
Diffstat (limited to 'app/services/error_tracking/issue_update_service.rb')
-rw-r--r-- | app/services/error_tracking/issue_update_service.rb | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/app/services/error_tracking/issue_update_service.rb b/app/services/error_tracking/issue_update_service.rb index e433b4a11f2..db754d54fef 100644 --- a/app/services/error_tracking/issue_update_service.rb +++ b/app/services/error_tracking/issue_update_service.rb @@ -4,6 +4,16 @@ module ErrorTracking class IssueUpdateService < ErrorTracking::BaseService private + def perform + response = fetch + + unless parse_errors(response).present? + response[:closed_issue_iid] = update_related_issue&.iid + end + + response + end + def fetch project_error_tracking_setting.update_issue( issue_id: params[:issue_id], @@ -11,12 +21,58 @@ module ErrorTracking ) end + def update_related_issue + issue = related_issue + return unless issue + + close_and_create_note(issue) + end + + def close_and_create_note(issue) + return unless resolving? && issue.opened? + + processed_issue = close_issue(issue) + return unless processed_issue.reset.closed? + + create_system_note(processed_issue) + processed_issue + end + + def close_issue(issue) + Issues::CloseService + .new(project, current_user) + .execute(issue, system_note: false) + end + + def create_system_note(issue) + SystemNoteService.close_after_error_tracking_resolve(issue, project, current_user) + end + + def related_issue + SentryIssueFinder + .new(project, current_user: current_user) + .execute(params[:issue_id]) + &.issue + end + + def resolving? + update_params[:status] == 'resolved' + end + def update_params params.except(:issue_id) end def parse_response(response) - { updated: response[:updated].present? } + { + updated: response[:updated].present?, + closed_issue_iid: response[:closed_issue_iid] + } + end + + def check_permissions + return error('Error Tracking is not enabled') unless enabled? + return error('Access denied', :unauthorized) unless can_update? end end end |