mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-07-21 23:43:41 +00:00
Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
@ -102,4 +102,26 @@ module DiffPositionableNote
|
||||
|
||||
errors.add(:commit_id, 'does not match the diff refs')
|
||||
end
|
||||
|
||||
def keep_around_commits
|
||||
repository.keep_around(*shas, source: "#{noteable_type}/#{self.class.name}")
|
||||
end
|
||||
|
||||
def repository
|
||||
noteable.respond_to?(:repository) ? noteable.repository : project.repository
|
||||
end
|
||||
|
||||
def shas
|
||||
[
|
||||
original_position.base_sha,
|
||||
original_position.start_sha,
|
||||
original_position.head_sha
|
||||
].tap do |a|
|
||||
if position != original_position
|
||||
a << position.base_sha
|
||||
a << position.start_sha
|
||||
a << position.head_sha
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -143,20 +143,6 @@ class DiffNote < Note
|
||||
position&.multiline?
|
||||
end
|
||||
|
||||
def shas
|
||||
[
|
||||
self.original_position.base_sha,
|
||||
self.original_position.start_sha,
|
||||
self.original_position.head_sha
|
||||
].tap do |a|
|
||||
if self.position != self.original_position
|
||||
a << self.position.base_sha
|
||||
a << self.position.start_sha
|
||||
a << self.position.head_sha
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def latest_diff_file_path
|
||||
latest_diff_file.file_path
|
||||
end
|
||||
@ -224,12 +210,4 @@ class DiffNote < Note
|
||||
|
||||
errors.add(:position, "is incomplete")
|
||||
end
|
||||
|
||||
def keep_around_commits
|
||||
repository.keep_around(*shas, source: "#{noteable_type}/#{self.class.name}")
|
||||
end
|
||||
|
||||
def repository
|
||||
noteable.respond_to?(:repository) ? noteable.repository : project.repository
|
||||
end
|
||||
end
|
||||
|
@ -47,6 +47,18 @@ class DraftNote < ApplicationRecord
|
||||
.map(&:position)
|
||||
end
|
||||
|
||||
def self.bulk_insert_and_keep_commits!(items, **options)
|
||||
inserted_records = bulk_insert!(items, **options)
|
||||
|
||||
keep_commits_for_records(items)
|
||||
|
||||
inserted_records
|
||||
end
|
||||
|
||||
def self.keep_commits_for_records(records)
|
||||
records.find(&:on_diff?)&.keep_around_commits
|
||||
end
|
||||
|
||||
def project
|
||||
merge_request.target_project
|
||||
end
|
||||
|
@ -36,6 +36,8 @@ module DraftNotes
|
||||
merge_request_activity_counter.track_create_review_note_action(user: current_user)
|
||||
end
|
||||
|
||||
draft_note.keep_around_commits if draft_note.on_diff?
|
||||
|
||||
after_execute
|
||||
|
||||
draft_note
|
||||
|
@ -119,4 +119,32 @@ RSpec.describe DraftNote, feature_category: :code_review_workflow do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.bulk_insert_and_keep_commits!' do
|
||||
let_it_be(:user) { create(:user) }
|
||||
let(:drafts) do
|
||||
[
|
||||
build(:draft_note, merge_request: merge_request, author: user),
|
||||
build(:draft_note_on_text_diff, merge_request: merge_request, author: user),
|
||||
build(:draft_note_on_text_diff, merge_request: merge_request, author: user)
|
||||
]
|
||||
end
|
||||
|
||||
it 'inserts items in the given number of batches' do
|
||||
expect(described_class)
|
||||
.to receive(:bulk_insert!)
|
||||
.with(drafts, batch_size: 5)
|
||||
.and_call_original
|
||||
|
||||
described_class.bulk_insert_and_keep_commits!(drafts, batch_size: 5)
|
||||
end
|
||||
|
||||
it 'calls keep_around_commits on the first draft note on diff' do
|
||||
expect(drafts[0]).not_to receive(:keep_around_commits)
|
||||
expect(drafts[1]).to receive(:keep_around_commits)
|
||||
expect(drafts[2]).not_to receive(:keep_around_commits) # This tests that we only keep around the first commit
|
||||
|
||||
described_class.bulk_insert_and_keep_commits!(drafts, batch_size: 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -20,6 +20,22 @@ RSpec.describe DraftNotes::CreateService, feature_category: :code_review_workflo
|
||||
expect(draft.discussion_id).to be_nil
|
||||
end
|
||||
|
||||
it 'creates keep-around refs' do
|
||||
diff_refs = project.commit(RepoHelpers.sample_commit.id).try(:diff_refs)
|
||||
|
||||
position = Gitlab::Diff::Position.new(
|
||||
old_path: "files/ruby/popen.rb",
|
||||
new_path: "files/ruby/popen.rb",
|
||||
old_line: nil,
|
||||
new_line: 14,
|
||||
diff_refs: diff_refs
|
||||
)
|
||||
|
||||
expect(project.repository).to receive(:keep_around)
|
||||
|
||||
create_draft(note: 'Comment on diff', position: position.to_json)
|
||||
end
|
||||
|
||||
it 'tracks the start event when the draft is persisted' do
|
||||
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
|
||||
.to receive(:track_create_review_note_action)
|
||||
|
Reference in New Issue
Block a user