Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-12 03:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-12 03:07:43 +0300
commit2e3cbf7d89815e2915f77677388c49b48f8d20c3 (patch)
tree03bdbc99e829295e8077b2ec4032300c15b48e37 /lib/gitlab/error_tracking
parente44bb86539a8fb4cfb06dfe281632b6f206bd0a7 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/error_tracking')
-rw-r--r--lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb b/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb
new file mode 100644
index 00000000000..a403275fd4e
--- /dev/null
+++ b/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module ErrorTracking
+ module StackTraceHighlightDecorator
+ extend self
+
+ def decorate(error_event)
+ ::Gitlab::ErrorTracking::ErrorEvent.new(
+ issue_id: error_event.issue_id,
+ date_received: error_event.date_received,
+ stack_trace_entries: highlight_stack_trace(error_event.stack_trace_entries)
+ )
+ end
+
+ private
+
+ def highlight_stack_trace(stack_trace)
+ stack_trace.map do |entry|
+ highlight_stack_trace_entry(entry)
+ end
+ end
+
+ def highlight_stack_trace_entry(entry)
+ return entry unless entry['context']
+
+ entry.merge('context' => highlight_entry_context(entry['filename'], entry['context']))
+ end
+
+ def highlight_entry_context(filename, context)
+ language = Rouge::Lexer.guess_by_filename(filename).tag
+
+ context.map do |line_number, line_of_code|
+ [
+ line_number,
+ # Passing nil for the blob name allows skipping linking dependencies for the line_of_code
+ Gitlab::Highlight.highlight(nil, line_of_code, language: language)
+ ]
+ end
+ end
+ end
+ end
+end