debian-mirror-gitlab/app/services/discussions/update_diff_position_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Discussions
class UpdateDiffPositionService < BaseService
def execute(discussion)
2019-09-30 21:07:59 +05:30
old_position = discussion.position
result = tracer.trace(old_position)
2017-09-10 17:25:29 +05:30
return unless result
position = result[:position]
outdated = result[:outdated]
discussion.notes.each do |note|
if outdated
note.change_position = position
2018-03-17 18:26:18 +05:30
if project.resolve_outdated_diff_discussions?
note.resolve_without_save(current_user, resolved_by_push: true)
end
2017-09-10 17:25:29 +05:30
else
note.position = position
note.change_position = nil
end
end
Note.transaction do
discussion.notes.each do |note|
2023-07-09 08:55:56 +05:30
note.save(touch: false)
2017-09-10 17:25:29 +05:30
end
if outdated && current_user
SystemNoteService.diff_discussion_outdated(discussion, project, current_user, position)
end
end
end
private
def tracer
@tracer ||= Gitlab::Diff::PositionTracer.new(
project: project,
old_diff_refs: params[:old_diff_refs],
new_diff_refs: params[:new_diff_refs],
paths: params[:paths]
)
end
end
end