Fix label links update on project transfer
This commit is contained in:
parent
0517e1d853
commit
470b3cb5a1
3 changed files with 23 additions and 3 deletions
|
@ -64,9 +64,14 @@ module Labels
|
|||
end
|
||||
|
||||
def update_label_links(labels, old_label_id:, new_label_id:)
|
||||
LabelLink.joins(:label)
|
||||
.merge(labels)
|
||||
.where(label_id: old_label_id)
|
||||
# use 'labels' relation to get label_link ids only of issues/MRs
|
||||
# in the project being transferred.
|
||||
# IDs are fetched in a separate query because MySQL doesn't
|
||||
# allow referring of 'label_links' table in UPDATE query:
|
||||
# https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/62435068
|
||||
link_ids = labels.pluck('label_links.id')
|
||||
|
||||
LabelLink.where(id: link_ids, label_id: old_label_id)
|
||||
.update_all(label_id: new_label_id)
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix label links update on project transfer
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -8,6 +8,7 @@ describe Labels::TransferService do
|
|||
let(:group_3) { create(:group) }
|
||||
let(:project_1) { create(:project, namespace: group_2) }
|
||||
let(:project_2) { create(:project, namespace: group_3) }
|
||||
let(:project_3) { create(:project, namespace: group_1) }
|
||||
|
||||
let(:group_label_1) { create(:group_label, group: group_1, name: 'Group Label 1') }
|
||||
let(:group_label_2) { create(:group_label, group: group_1, name: 'Group Label 2') }
|
||||
|
@ -23,6 +24,7 @@ describe Labels::TransferService do
|
|||
create(:labeled_issue, project: project_1, labels: [group_label_4])
|
||||
create(:labeled_issue, project: project_1, labels: [project_label_1])
|
||||
create(:labeled_issue, project: project_2, labels: [group_label_5])
|
||||
create(:labeled_issue, project: project_3, labels: [group_label_1])
|
||||
create(:labeled_merge_request, source_project: project_1, labels: [group_label_1, group_label_2])
|
||||
create(:labeled_merge_request, source_project: project_2, labels: [group_label_5])
|
||||
end
|
||||
|
@ -52,5 +54,13 @@ describe Labels::TransferService do
|
|||
|
||||
expect(project_1.labels.where(title: group_label_4.title)).to be_empty
|
||||
end
|
||||
|
||||
it 'updates only label links in the given project' do
|
||||
service.execute
|
||||
|
||||
targets = LabelLink.where(label_id: group_label_1.id).map(&:target)
|
||||
|
||||
expect(targets).to eq(project_3.issues)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue