diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-08-04 20:43:49 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-08-04 20:43:49 +0300 |
commit | af5faaf0e1e001558302704a421eb01f5e7a26ea (patch) | |
tree | a53ed55cd7b35f23f74ebe33b6610c77fafec132 /app/models/note.rb | |
parent | 8f05fbbab5754b2a05547bae7ed3f9c409d8a640 (diff) | |
download | gitlab-ce-af5faaf0e1e001558302704a421eb01f5e7a26ea.tar.gz |
Move diff parsing to own class. Correctly identify note diff line
Diffstat (limited to 'app/models/note.rb')
-rw-r--r-- | app/models/note.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 8714db2e10e..697c9d03a93 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -51,7 +51,7 @@ class Note < ActiveRecord::Base scope :inc_author, ->{ includes(:author) } serialize :st_diff - before_create :set_diff, if: ->(n) { n.noteable_type == 'MergeRequest' && n.line_code.present? } + before_create :set_diff, if: ->(n) { n.line_code.present? } def self.create_status_change_note(noteable, author, status) create({ @@ -81,7 +81,7 @@ class Note < ActiveRecord::Base def set_diff # First lets find notes with same diff # before iterating over all mr diffs - diff = self.noteable.notes.where(line_code: self.line_code).last.try(:diff) + diff = Note.where(noteable_id: self.noteable_id, noteable_type: self.noteable_type, line_code: self.line_code).last.try(:diff) diff ||= find_diff self.st_diff = diff.to_hash if diff @@ -91,6 +91,12 @@ class Note < ActiveRecord::Base @diff ||= Gitlab::Git::Diff.new(st_diff) if st_diff.respond_to?(:map) end + def active? + # TODO: determine if discussion is outdated + # according to recent MR diff or not + true + end + def diff_file_index line_code.split('_')[0] end @@ -108,10 +114,15 @@ class Note < ActiveRecord::Base end def diff_line + return @diff_line if @diff_line + if diff - @diff_line ||= diff.diff.lines.select { |line| line =~ /\A\+/ }[diff_new_line] || - diff.diff.lines.select { |line| line =~ /\A\-/ }[diff_old_line] + Gitlab::DiffParser.new(diff).each do |full_line, type, line_code, line_new, line_old| + @diff_line = full_line if line_code == self.line_code + end end + + @diff_line end def discussion_id |