Commit 428c3b1d authored by Patrick Bajao's avatar Patrick Bajao

Link LFS objects when MR is created

This is to avoid errors when pulling LFS objects in context of
the MR's target project.
parent 122a87b1
......@@ -21,8 +21,9 @@ module LfsObjectsProjects
private
# rubocop: disable CodeReuse/ActiveRecord
def lfs_objects_projects_map(target_project)
project.lfs_objects_projects.map do |objects_project|
project.lfs_objects_projects.where.not(lfs_object: target_project.lfs_objects).map do |objects_project|
{
lfs_object_id: objects_project.lfs_object_id,
project_id: target_project.id,
......@@ -30,5 +31,6 @@ module LfsObjectsProjects
}
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -27,6 +27,7 @@ module MergeRequests
create_pipeline_for(issuable, current_user)
issuable.update_head_pipeline
Gitlab::UsageDataCounters::MergeRequestCounter.count(:create)
link_lfs_objects(issuable)
super
end
......@@ -64,6 +65,14 @@ module MergeRequests
raise Gitlab::Access::AccessDeniedError
end
end
def link_lfs_objects(issuable)
return if issuable.source_project == issuable.target_project
LfsObjectsProjects::BulkCreateService
.new(issuable.source_project, target_project: issuable.target_project)
.execute
end
end
end
......
......@@ -483,6 +483,14 @@ describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do
expect(merge_request).to be_persisted
end
it 'calls LfsObjectsProjects::BulkCreateService#execute', :sidekiq_might_not_need_inline do
expect_next_instance_of(LfsObjectsProjects::BulkCreateService) do |service|
expect(service).to receive(:execute)
end
described_class.new(project, user, opts).execute
end
it 'does not create the merge request when the target project is archived' do
target_project.update!(archived: true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment