Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
470b3cb5
Commit
470b3cb5
authored
Apr 19, 2018
by
Jan Provaznik
Committed by
Sean McGivern
Apr 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix label links update on project transfer
parent
0517e1d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
app/services/labels/transfer_service.rb
app/services/labels/transfer_service.rb
+8
-3
changelogs/unreleased/label-links-on-project-transfer.yml
changelogs/unreleased/label-links-on-project-transfer.yml
+5
-0
spec/services/labels/transfer_service_spec.rb
spec/services/labels/transfer_service_spec.rb
+10
-0
No files found.
app/services/labels/transfer_service.rb
View file @
470b3cb5
...
@@ -64,9 +64,14 @@ module Labels
...
@@ -64,9 +64,14 @@ module Labels
end
end
def
update_label_links
(
labels
,
old_label_id
:,
new_label_id
:)
def
update_label_links
(
labels
,
old_label_id
:,
new_label_id
:)
LabelLink
.
joins
(
:label
)
# use 'labels' relation to get label_link ids only of issues/MRs
.
merge
(
labels
)
# in the project being transferred.
.
where
(
label_id:
old_label_id
)
# 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
)
.
update_all
(
label_id:
new_label_id
)
end
end
...
...
changelogs/unreleased/label-links-on-project-transfer.yml
0 → 100644
View file @
470b3cb5
---
title
:
Fix label links update on project transfer
merge_request
:
author
:
type
:
fixed
spec/services/labels/transfer_service_spec.rb
View file @
470b3cb5
...
@@ -8,6 +8,7 @@ describe Labels::TransferService do
...
@@ -8,6 +8,7 @@ describe Labels::TransferService do
let
(
:group_3
)
{
create
(
:group
)
}
let
(
:group_3
)
{
create
(
:group
)
}
let
(
:project_1
)
{
create
(
:project
,
namespace:
group_2
)
}
let
(
:project_1
)
{
create
(
:project
,
namespace:
group_2
)
}
let
(
:project_2
)
{
create
(
:project
,
namespace:
group_3
)
}
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_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'
)
}
let
(
:group_label_2
)
{
create
(
:group_label
,
group:
group_1
,
name:
'Group Label 2'
)
}
...
@@ -23,6 +24,7 @@ describe Labels::TransferService do
...
@@ -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:
[
group_label_4
])
create
(
:labeled_issue
,
project:
project_1
,
labels:
[
project_label_1
])
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_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_1
,
labels:
[
group_label_1
,
group_label_2
])
create
(
:labeled_merge_request
,
source_project:
project_2
,
labels:
[
group_label_5
])
create
(
:labeled_merge_request
,
source_project:
project_2
,
labels:
[
group_label_5
])
end
end
...
@@ -52,5 +54,13 @@ describe Labels::TransferService do
...
@@ -52,5 +54,13 @@ describe Labels::TransferService do
expect
(
project_1
.
labels
.
where
(
title:
group_label_4
.
title
)).
to
be_empty
expect
(
project_1
.
labels
.
where
(
title:
group_label_4
.
title
)).
to
be_empty
end
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
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment