Class: MergeRequests::OutdatedDiscussionDiffLinesService
- Inherits:
-
Object
- Object
- MergeRequests::OutdatedDiscussionDiffLinesService
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/merge_requests/outdated_discussion_diff_lines_service.rb
Constant Summary collapse
- OVERFLOW_LINES_COUNT =
2
Instance Attribute Summary collapse
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(project:, note:) ⇒ OutdatedDiscussionDiffLinesService
constructor
A new instance of OutdatedDiscussionDiffLinesService.
Constructor Details
#initialize(project:, note:) ⇒ OutdatedDiscussionDiffLinesService
Returns a new instance of OutdatedDiscussionDiffLinesService.
11 12 13 14 |
# File 'app/services/merge_requests/outdated_discussion_diff_lines_service.rb', line 11 def initialize(project:, note:) @project = project @note = note end |
Instance Attribute Details
#note ⇒ Object (readonly)
Returns the value of attribute note.
7 8 9 |
# File 'app/services/merge_requests/outdated_discussion_diff_lines_service.rb', line 7 def note @note end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
7 8 9 |
# File 'app/services/merge_requests/outdated_discussion_diff_lines_service.rb', line 7 def project @project end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/merge_requests/outdated_discussion_diff_lines_service.rb', line 16 def execute line_position = position.line_range["end"] || position.line_range["start"] found_line = false diff_line_index = -1 diff_lines.each_with_index do |l, i| if found_line if !l.type break elsif l.type == 'new' diff_line_index = i break end else # Find the old line found_line = l.old_line == line_position["new_line"] end diff_line_index = i end initial_line_index = [diff_line_index - OVERFLOW_LINES_COUNT, 0].max last_line_index = [diff_line_index + OVERFLOW_LINES_COUNT, diff_lines.length].min prev_lines = [] diff_lines[initial_line_index..last_line_index].each do |line| if line. prev_lines.clear else prev_lines << line end end prev_lines end |