Class: Discussions::CaptureDiffNotePositionService

Inherits:
Object
  • Object
show all
Defined in:
app/services/discussions/capture_diff_note_position_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(merge_request, paths) ⇒ CaptureDiffNotePositionService

Returns a new instance of CaptureDiffNotePositionService.


5
6
7
8
# File 'app/services/discussions/capture_diff_note_position_service.rb', line 5

def initialize(merge_request, paths)
  @project = merge_request.project
  @tracer = build_tracer(merge_request, paths)
end

Instance Method Details

#execute(discussion) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/discussions/capture_diff_note_position_service.rb', line 10

def execute(discussion)
  # The service has been implemented for text only
  # The impact of image notes on this service is being investigated in
  # https://gitlab.com/gitlab-org/gitlab/-/issues/213989
  return unless discussion.on_text?

  result = tracer&.trace(discussion.position)
  return unless result

  position = result[:position]
  return unless position

  line_code = position.line_code(project.repository)
  return unless line_code

  # Currently position data is copied across all notes of a discussion
  # It makes sense to store a position only for the first note instead
  # Within the newly introduced table we can start doing just that
  DiffNotePosition.create_or_update_for(discussion.notes.first,
    diff_type: :head,
    position: position,
    line_code: line_code)
end