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
Léo-Paul Géneau
gitlab-ce
Commits
2d2adf42
Commit
2d2adf42
authored
Jul 05, 2018
by
Jan Provaznik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed pluck and renamed methods
parent
3bf7444e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
lib/gitlab/background_migration/fix_cross_project_label_links.rb
...lab/background_migration/fix_cross_project_label_links.rb
+8
-7
No files found.
lib/gitlab/background_migration/fix_cross_project_label_links.rb
View file @
2d2adf42
...
...
@@ -49,10 +49,10 @@ module Gitlab
def
perform
(
start_id
,
stop_id
)
group_ids
=
Namespace
.
groups_with_descendants_ids
(
start_id
,
stop_id
)
project_ids
=
Project
.
where
(
namespace_id:
group_ids
).
pluck
(
:id
)
project_ids
=
Project
.
where
(
namespace_id:
group_ids
).
select
(
:id
)
check
_issues
(
project_ids
)
check
_merge_requests
(
project_ids
)
fix
_issues
(
project_ids
)
fix
_merge_requests
(
project_ids
)
end
private
...
...
@@ -60,7 +60,7 @@ module Gitlab
# select IDs of issues which reference a label which is:
# a) a project label of a different project, or
# b) a group label of a different group than issue's project group
def
check
_issues
(
project_ids
)
def
fix
_issues
(
project_ids
)
issue_ids
=
Label
.
joins
(
'INNER JOIN label_links ON label_links.label_id = labels.id AND label_links.target_type = \'Issue\'
INNER JOIN issues ON issues.id = label_links.target_id
...
...
@@ -68,7 +68,7 @@ module Gitlab
.
where
(
'issues.project_id in (?)'
,
project_ids
)
.
where
(
'(labels.project_id is not null and labels.project_id != issues.project_id) '
\
'or (labels.group_id is not null and labels.group_id != projects.namespace_id)'
)
.
pluck
(
'distinct issues.id'
)
.
select
(
'distinct issues.id'
)
Issue
.
where
(
id:
issue_ids
).
find_each
{
|
issue
|
check_resource_labels
(
issue
,
issue
.
project_id
)
}
end
...
...
@@ -76,7 +76,7 @@ module Gitlab
# select IDs of MRs which reference a label which is:
# a) a project label of a different project, or
# b) a group label of a different group than MR's project group
def
check
_merge_requests
(
project_ids
)
def
fix
_merge_requests
(
project_ids
)
mr_ids
=
Label
.
joins
(
'INNER JOIN label_links ON label_links.label_id = labels.id AND label_links.target_type = \'MergeRequest\'
INNER JOIN merge_requests ON merge_requests.id = label_links.target_id
...
...
@@ -84,7 +84,7 @@ module Gitlab
.
where
(
'merge_requests.target_project_id in (?)'
,
project_ids
)
.
where
(
'(labels.project_id is not null and labels.project_id != merge_requests.target_project_id) '
\
'or (labels.group_id is not null and labels.group_id != projects.namespace_id)'
)
.
pluck
(
'distinct merge_requests.id'
)
.
select
(
'distinct merge_requests.id'
)
MergeRequest
.
where
(
id:
mr_ids
).
find_each
{
|
merge_request
|
check_resource_labels
(
merge_request
,
merge_request
.
target_project_id
)
}
end
...
...
@@ -106,6 +106,7 @@ module Gitlab
next
unless
matching_label
Rails
.
logger
.
info
"
#{
resource
.
class
.
name
.
demodulize
}
#{
resource
.
id
}
: replacing
#{
label
.
label_id
}
with
#{
matching_label
.
id
}
"
LabelLink
.
update
(
label
.
label_link_id
,
label_id:
matching_label
.
id
)
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