2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-16 11:46:18 -04:00
|
|
|
class NoteDiffFile < ActiveRecord::Base
|
|
|
|
include DiffFile
|
|
|
|
|
2018-12-16 11:00:43 -05:00
|
|
|
scope :for_commit_or_unresolved, -> do
|
|
|
|
joins(:diff_note).where("resolved_at IS NULL OR noteable_type = 'Commit'")
|
|
|
|
end
|
|
|
|
|
|
|
|
delegate :original_position, :project, to: :diff_note
|
|
|
|
|
2018-05-16 11:46:18 -04:00
|
|
|
belongs_to :diff_note, inverse_of: :note_diff_file
|
|
|
|
|
|
|
|
validates :diff_note, presence: true
|
2018-12-16 11:00:43 -05:00
|
|
|
|
|
|
|
def raw_diff_file
|
|
|
|
raw_diff = Gitlab::Git::Diff.new(to_hash)
|
|
|
|
|
|
|
|
Gitlab::Diff::File.new(raw_diff,
|
|
|
|
repository: project.repository,
|
|
|
|
diff_refs: original_position.diff_refs,
|
|
|
|
unique_identifier: id)
|
|
|
|
end
|
2018-05-16 11:46:18 -04:00
|
|
|
end
|