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
375bf7d9
Commit
375bf7d9
authored
Dec 18, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set MR rule to point to project MR
parent
840cb644
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
4 deletions
+53
-4
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules.rb
...ackground_migration/migrate_approver_to_approval_rules.rb
+14
-4
ee/spec/lib/gitlab/background_migration/migrate_approver_to_approval_rules_in_batch_spec.rb
...ation/migrate_approver_to_approval_rules_in_batch_spec.rb
+17
-0
ee/spec/lib/gitlab/background_migration/migrate_approver_to_approval_rules_spec.rb
...ound_migration/migrate_approver_to_approval_rules_spec.rb
+22
-0
No files found.
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules.rb
View file @
375bf7d9
...
...
@@ -29,6 +29,8 @@ module Gitlab
has_and_belongs_to_many
:groups
,
class_name:
'Group'
,
join_table: :approval_merge_request_rules_groups
has_and_belongs_to_many
:approvals
# This is only populated after merge request is merged
has_many
:approved_approvers
,
through: :approvals
,
source: :user
has_one
:approval_merge_request_rule_source
has_one
:approval_project_rule
,
through: :approval_merge_request_rule_source
def
project
merge_request
.
target_project
...
...
@@ -63,6 +65,12 @@ module Gitlab
end
end
class
ApprovalMergeRequestRuleSource
<
ApplicationRecord
self
.
table_name
=
'approval_merge_request_rule_sources'
belongs_to
:approval_merge_request_rule
belongs_to
:approval_project_rule
end
class
ApprovalProjectRule
<
ActiveRecord
::
Base
self
.
table_name
=
'approval_project_rules'
...
...
@@ -158,7 +166,10 @@ module Gitlab
def
handle_merge_request
ActiveRecord
::
Base
.
transaction
do
sync_rule
if
rule
=
sync_rule
rule
.
approval_project_rule
=
target
.
target_project
.
approval_rules
.
regular
.
first
end
target
.
finalize_approvals
if
target
.
merged?
end
end
...
...
@@ -171,7 +182,6 @@ module Gitlab
schedule_to_migrate_merge_requests
(
target
)
end
# Sync users and groups on rule
def
sync_rule
unless
approvers_exists?
target
.
approval_rules
.
regular
.
delete_all
...
...
@@ -179,9 +189,9 @@ module Gitlab
end
rule
=
find_or_create_rule
rule
.
user_ids
=
target
.
approvers
.
pluck
(
:user_id
)
rule
.
group_ids
=
target
.
approver_groups
.
pluck
(
:group_id
)
rule
end
def
schedule_to_migrate_merge_requests
(
project
)
...
...
@@ -204,7 +214,7 @@ module Gitlab
end
def
find_or_create_rule
rule
=
target
.
approval_rules
.
find_or_initialize_by
(
name:
'Default'
)
rule
=
target
.
approval_rules
.
regular
.
find_or_initialize_by
(
name:
'Default'
)
unless
rule
.
persisted?
rule
.
approvals_required
=
target
.
approvals_before_merge
||
0
...
...
ee/spec/lib/gitlab/background_migration/migrate_approver_to_approval_rules_in_batch_spec.rb
0 → 100644
View file @
375bf7d9
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRulesInBatch
do
context
'when there is no more MigrateApproverToApprovalRules jobs'
do
let
(
:job
)
{
double
(
:job
)
}
it
'enables feature'
do
allow
(
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRules
).
to
receive
(
:new
).
and_return
(
job
)
expect
(
job
).
to
receive
(
:perform
).
exactly
(
3
).
times
described_class
.
new
.
perform
(
'Foo'
,
[
1
,
2
,
3
])
end
end
end
ee/spec/lib/gitlab/background_migration/migrate_approver_to_approval_rules_spec.rb
View file @
375bf7d9
...
...
@@ -83,6 +83,28 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do
it_behaves_like
'sync approval member'
context
'when project rule is present'
do
let!
(
:project_rule
)
{
create
(
:approval_project_rule
,
project:
target
.
target_project
)
}
it
"sets MR rule's source to project rule"
do
create_member_in
(
create
(
:user
),
:old_schema
)
described_class
.
new
.
perform
(
target_type
,
target
.
id
)
expect
(
target
.
approval_rules
.
regular
.
first
.
approval_project_rule
).
to
eq
(
project_rule
)
end
end
context
'when project rule is absent'
do
it
"has MR rule's source as nil"
do
create_member_in
(
create
(
:user
),
:old_schema
)
described_class
.
new
.
perform
(
target_type
,
target
.
id
)
expect
(
target
.
approval_rules
.
regular
.
first
.
approval_project_rule
).
to
eq
(
nil
)
end
end
context
'when approver is no longer overwritten'
do
before
do
create_member_in
(
create
(
:user
),
:new_schema
)
...
...
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