Module: DiffPositionableNote

Extended by:
ActiveSupport::Concern
Included in:
DiffNote, DraftNote
Defined in:
app/models/concerns/diff_positionable_note.rb

Instance Method Summary collapse

Instance Method Details

#active?(diff_refs = nil) ⇒ Boolean

Returns:

  • (Boolean)

40
41
42
43
44
45
46
47
# File 'app/models/concerns/diff_positionable_note.rb', line 40

def active?(diff_refs = nil)
  return false unless supported?
  return true if for_commit?

  diff_refs ||= noteable.diff_refs

  self.position.diff_refs == diff_refs
end

#diff_refs_match_commitObject


79
80
81
82
83
# File 'app/models/concerns/diff_positionable_note.rb', line 79

def diff_refs_match_commit
  return if self.original_position.diff_refs == commit&.diff_refs

  errors.add(:commit_id, 'does not match the diff refs')
end

#set_original_positionObject


49
50
51
52
53
# File 'app/models/concerns/diff_positionable_note.rb', line 49

def set_original_position
  return unless position

  self.original_position = self.position.dup unless self.original_position&.complete?
end

#supported?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/models/concerns/diff_positionable_note.rb', line 36

def supported?
  for_commit? || self.noteable.has_complete_diff_refs?
end

#update_positionObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/concerns/diff_positionable_note.rb', line 55

def update_position
  return unless supported?
  return if for_commit?

  return if active?
  return unless position

  tracer = Gitlab::Diff::PositionTracer.new(
    project: self.project,
    old_diff_refs: self.position.diff_refs,
    new_diff_refs: self.noteable.diff_refs,
    paths: self.position.paths
  )

  result = tracer.trace(self.position)
  return unless result

  if result[:outdated]
    self.change_position = result[:position]
  else
    self.position = result[:position]
  end
end