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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
1f320d1c
Commit
1f320d1c
authored
Jul 05, 2018
by
Jan Provaznik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for MRs
parent
d785295f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
40 deletions
+67
-40
lib/gitlab/background_migration/fix_cross_project_label_links.rb
...lab/background_migration/fix_cross_project_label_links.rb
+1
-1
spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb
...ackground_migration/fix_cross_project_label_links_spec.rb
+66
-39
No files found.
lib/gitlab/background_migration/fix_cross_project_label_links.rb
View file @
1f320d1c
...
...
@@ -106,7 +106,7 @@ module Gitlab
next
unless
matching_label
LabelLink
.
find
(
label
.
label_link_id
).
update!
(
label_id:
matching_label
.
id
)
LabelLink
.
update
(
label
.
label_link_id
,
label_id:
matching_label
.
id
)
end
end
...
...
spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb
View file @
1f320d1c
...
...
@@ -17,66 +17,93 @@ describe Gitlab::BackgroundMigration::FixCrossProjectLabelLinks, :migration, sch
let!
(
:label1
)
{
labels_table
.
create
(
id:
1
,
title:
'bug'
,
color:
'red'
,
group_id:
10
,
type:
'GroupLabel'
)
}
let!
(
:label2
)
{
labels_table
.
create
(
id:
2
,
title:
'bug'
,
color:
'red'
,
group_id:
20
,
type:
'GroupLabel'
)
}
let
(
:merge_request
)
do
merge_requests_table
.
create
(
target_project_id:
project
.
id
,
def
create_merge_request
(
id
,
project_id
)
merge_requests_table
.
create
(
id:
id
,
target_project_id:
project_id
,
target_branch:
'master'
,
source_project_id:
project
.
id
,
source_project_id:
project
_
id
,
source_branch:
'mr name'
,
title:
'mr name'
)
title:
"mr name
#{
id
}
"
)
end
it
'updates cross-project label links which exist in the local project or group'
do
issues_table
.
create
(
id:
1
,
title:
'issue1'
,
project_id:
1
)
link
=
label_links_table
.
create
(
label_id:
2
,
target_type:
'Issue'
,
target_id:
1
)
subject
.
perform
(
1
,
100
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
1
)
def
create_issue
(
id
,
project_id
)
issues_table
.
create
(
id:
id
,
title:
"issue
#{
id
}
"
,
project_id:
project_id
)
end
it
'ignores cross-project label links if label color is different'
do
labels_table
.
create
(
id:
3
,
title:
'bug'
,
color:
'green'
,
group_id:
20
,
type:
'GroupLabel'
)
issues_table
.
create
(
id:
1
,
title:
'issue1'
,
project_id:
1
)
link
=
label_links_table
.
create
(
label_id:
3
,
target_type:
'Issue'
,
target_id:
1
)
def
create_resource
(
target_type
,
id
,
project_id
)
target_type
==
'Issue'
?
create_issue
(
id
,
project_id
)
:
create_merge_request
(
id
,
project_id
)
end
subject
.
perform
(
1
,
100
)
shared_examples_for
'resource with cross-project labels'
do
it
'updates only cross-project label links which exist in the local project or group'
do
create_resource
(
target_type
,
1
,
1
)
create_resource
(
target_type
,
2
,
3
)
labels_table
.
create
(
id:
3
,
title:
'bug'
,
color:
'red'
,
project_id:
3
,
type:
'ProjectLabel'
)
link
=
label_links_table
.
create
(
label_id:
2
,
target_type:
target_type
,
target_id:
1
)
link2
=
label_links_table
.
create
(
label_id:
3
,
target_type:
target_type
,
target_id:
2
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
3
)
end
subject
.
perform
(
1
,
100
)
it
'ignores cross-project label links if label name is different'
do
labels_table
.
create
(
id:
3
,
title:
'bug1'
,
color:
'red'
,
group_id:
20
,
type:
'GroupLabel'
)
issues_table
.
create
(
id:
1
,
title:
'issue1'
,
project_id:
1
)
link
=
label_links_table
.
create
(
label_id:
3
,
target_type:
'Issue'
,
target_id:
1
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
1
)
expect
(
link2
.
reload
.
label_id
).
to
eq
(
3
)
end
subject
.
perform
(
1
,
100
)
it
'ignores cross-project label links if label color is different'
do
labels_table
.
create
(
id:
3
,
title:
'bug'
,
color:
'green'
,
group_id:
20
,
type:
'GroupLabel'
)
create_resource
(
target_type
,
1
,
1
)
link
=
label_links_table
.
create
(
label_id:
3
,
target_type:
target_type
,
target_id:
1
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
3
)
end
subject
.
perform
(
1
,
100
)
context
'with nested group'
do
before
do
namespaces_table
.
create
(
id:
11
,
type:
'Group'
,
name:
'subgroup1'
,
path:
'group1/subgroup1'
,
parent_id:
10
)
projects_table
.
create
(
id:
2
,
name:
'subproject1'
,
path:
'group1/subgroup1/subproject1'
,
namespace_id:
11
)
issues_table
.
create
(
id:
1
,
title:
'issue1'
,
project_id:
2
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
3
)
end
it
'ignores
label links referencing ancestor group labels'
,
:nested_groups
do
labels_table
.
create
(
id:
4
,
title:
'bug'
,
color:
'red'
,
project_id:
2
,
type:
'Project
Label'
)
label_links_table
.
create
(
label_id:
4
,
target_type:
'Issue'
,
target_id:
1
)
link
=
label_links_table
.
create
(
label_id:
1
,
target_type:
'Issue'
,
target_id:
1
)
it
'ignores
cross-project label links if label name is different'
do
labels_table
.
create
(
id:
3
,
title:
'bug1'
,
color:
'red'
,
group_id:
20
,
type:
'Group
Label'
)
create_resource
(
target_type
,
1
,
1
)
link
=
label_links_table
.
create
(
label_id:
3
,
target_type:
target_type
,
target_id:
1
)
subject
.
perform
(
1
,
100
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
1
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
3
)
end
it
'checks also issues and MRs in subgroups'
,
:nested_groups
do
link
=
label_links_table
.
create
(
label_id:
2
,
target_type:
'Issue'
,
target_id:
1
)
context
'with nested group'
do
before
do
namespaces_table
.
create
(
id:
11
,
type:
'Group'
,
name:
'subgroup1'
,
path:
'group1/subgroup1'
,
parent_id:
10
)
projects_table
.
create
(
id:
2
,
name:
'subproject1'
,
path:
'group1/subgroup1/subproject1'
,
namespace_id:
11
)
create_resource
(
target_type
,
1
,
2
)
end
subject
.
perform
(
1
,
100
)
it
'ignores label links referencing ancestor group labels'
,
:nested_groups
do
labels_table
.
create
(
id:
4
,
title:
'bug'
,
color:
'red'
,
project_id:
2
,
type:
'ProjectLabel'
)
label_links_table
.
create
(
label_id:
4
,
target_type:
target_type
,
target_id:
1
)
link
=
label_links_table
.
create
(
label_id:
1
,
target_type:
target_type
,
target_id:
1
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
1
)
subject
.
perform
(
1
,
100
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
1
)
end
it
'checks also issues and MRs in subgroups'
,
:nested_groups
do
link
=
label_links_table
.
create
(
label_id:
2
,
target_type:
target_type
,
target_id:
1
)
subject
.
perform
(
1
,
100
)
expect
(
link
.
reload
.
label_id
).
to
eq
(
1
)
end
end
end
context
'resource is Issue'
do
it_behaves_like
'resource with cross-project labels'
do
let
(
:target_type
)
{
'Issue'
}
end
end
context
'resource is Merge Request'
do
it_behaves_like
'resource with cross-project labels'
do
let
(
:target_type
)
{
'MergeRequest'
}
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