summaryrefslogtreecommitdiff
path: root/app/services/notes/diff_position_update_service.rb
blob: 0cb731f5bc3f6cd6885f5556f375bce7b35962a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Notes
  class DiffPositionUpdateService < BaseService
    def execute(note)
      new_position = tracer.trace(note.position)

      # Don't update the position if the type doesn't match, since that means
      # the diff line commented on was changed, and the comment is now outdated
      old_position = note.position
      if new_position &&
          new_position != old_position &&
          new_position.type == old_position.type

        note.position = new_position
      end

      note
    end

    private

    def tracer
      @tracer ||= Gitlab::Diff::PositionTracer.new(
        repository: project.repository,
        old_diff_refs: params[:old_diff_refs],
        new_diff_refs: params[:new_diff_refs],
        paths: params[:paths]
      )
    end
  end
end