summaryrefslogtreecommitdiff
path: root/app/models/discussion.rb
diff options
context:
space:
mode:
authorhhoopes <heidih@gmail.com>2016-08-25 10:38:07 -0600
committerSean McGivern <sean@gitlab.com>2016-11-25 15:23:49 +0000
commitf928dba99b0550cefa7534d7fd5bd1ea16609274 (patch)
tree59414f92b38a10f154dd2035053d2b7f56461046 /app/models/discussion.rb
parent24070bac45134c915c13d3e94723a44f59ab4e3a (diff)
downloadgitlab-ce-f928dba99b0550cefa7534d7fd5bd1ea16609274.tar.gz
Change diff highlight/truncate for reusability
Previously the `truncated_diff_lines` method for outputting a discussion diff took in already highlighted lines, which meant it wasn't reuseable for truncating ANY lines. In the way it was used, it also meant that for any email truncation, the whole diff was being highlighted before being truncated, meaning wasted time highlighting lines that wouldn't even be used (granted, they were being memoized, so perhaps this wasn't that great of an issue). I refactored truncation away from highlighting, in order to truncate formatted diffs for text templates in email, using `>`s to designate each line, but otherwise retaining the parsing already done to create `diff_lines`. Additionally, while notes on merge requests or commits had already been tested, there was no existing test for notes on a diff on an MR or commit. Added mailer tests for such, and a unit test for truncating diff lines.
Diffstat (limited to 'app/models/discussion.rb')
-rw-r--r--app/models/discussion.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index de06c13481a..486bfd2c766 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -25,7 +25,12 @@ class Discussion
to: :last_resolved_note,
allow_nil: true
- delegate :blob, :highlighted_diff_lines, to: :diff_file, allow_nil: true
+ delegate :blob,
+ :highlighted_diff_lines,
+ :text_parsed_diff_lines,
+
+ to: :diff_file,
+ allow_nil: true
def self.for_notes(notes)
notes.group_by(&:discussion_id).values.map { |notes| new(notes) }
@@ -162,18 +167,15 @@ class Discussion
def truncated_diff_lines
prev_lines = []
- highlighted_diff_lines.each do |line|
+ diff_file.diff_lines.each do |line|
if line.meta?
prev_lines.clear
else
prev_lines << line
-
break if for_line?(line)
-
prev_lines.shift if prev_lines.length >= NUMBER_OF_TRUNCATED_DIFF_LINES
end
end
-
prev_lines
end