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
7f80b6ed
Commit
7f80b6ed
authored
Jan 05, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change to map MR rule to approved approvers directly
This is more direct in loggin who approved a rule.
parent
72c9b8a9
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
35 deletions
+25
-35
db/schema.rb
db/schema.rb
+6
-6
ee/app/models/approval.rb
ee/app/models/approval.rb
+0
-1
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+5
-5
ee/app/services/approval_rules/finalize_service.rb
ee/app/services/approval_rules/finalize_service.rb
+1
-1
ee/db/migrate/20181204031329_create_approval_rules_approvals.rb
...migrate/20181204031329_create_approval_rules_approvals.rb
+4
-4
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+5
-5
ee/spec/services/approval_rules/finalize_service_spec.rb
ee/spec/services/approval_rules/finalize_service_spec.rb
+4
-13
No files found.
db/schema.rb
View file @
7f80b6ed
...
...
@@ -236,11 +236,11 @@ ActiveRecord::Schema.define(version: 20190103140724) do
t
.
index
[
"merge_request_id"
,
"code_owner"
],
name:
"index_approval_merge_request_rules_1"
,
using: :btree
end
create_table
"approval_merge_request_rules_approv
al
s"
,
id: :bigserial
,
force: :cascade
do
|
t
|
create_table
"approval_merge_request_rules_approv
ed_approver
s"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
bigint
"approval_merge_request_rule_id"
,
null:
false
t
.
integer
"
approval
_id"
,
null:
false
t
.
index
[
"approval_
id"
],
name:
"index_approval_merge_request_rules_approvals_2"
,
using: :btree
t
.
index
[
"
approval_merge_request_rule_id"
,
"approval_id"
],
name:
"index_approval_merge_request_rules_approvals_1"
,
unique:
true
,
using: :btree
t
.
integer
"
user
_id"
,
null:
false
t
.
index
[
"approval_
merge_request_rule_id"
,
"user_id"
],
name:
"index_approval_merge_request_rules_approved_approvers_1"
,
unique:
true
,
using: :btree
t
.
index
[
"
user_id"
],
name:
"index_approval_merge_request_rules_approved_approvers_2"
,
using: :btree
end
create_table
"approval_merge_request_rules_groups"
,
id: :bigserial
,
force: :cascade
do
|
t
|
...
...
@@ -3227,8 +3227,8 @@ ActiveRecord::Schema.define(version: 20190103140724) do
add_foreign_key
"approval_merge_request_rule_sources"
,
"approval_merge_request_rules"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rule_sources"
,
"approval_project_rules"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules"
,
"merge_requests"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules_approv
al
s"
,
"approval_merge_request_rules"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules_approv
als"
,
"approval
s"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules_approv
ed_approver
s"
,
"approval_merge_request_rules"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules_approv
ed_approvers"
,
"user
s"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules_groups"
,
"approval_merge_request_rules"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules_groups"
,
"namespaces"
,
column:
"group_id"
,
on_delete: :cascade
add_foreign_key
"approval_merge_request_rules_users"
,
"approval_merge_request_rules"
,
on_delete: :cascade
...
...
ee/app/models/approval.rb
View file @
7f80b6ed
...
...
@@ -3,7 +3,6 @@
class
Approval
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:merge_request
has_and_belongs_to_many
:approval_rules
,
class_name:
'ApprovalMergeRequestRule'
,
join_table: :approval_merge_request_rules_approvals
validates
:merge_request_id
,
presence:
true
validates
:user_id
,
presence:
true
,
uniqueness:
{
scope:
[
:merge_request_id
]
}
...
...
ee/app/models/approval_merge_request_rule.rb
View file @
7f80b6ed
...
...
@@ -8,8 +8,8 @@ class ApprovalMergeRequestRule < ApplicationRecord
belongs_to
:merge_request
has_and_belongs_to_many
:approvals
# This is only populated after merge request
is merged
has_
many
:approved_approvers
,
through: :approvals
,
source: :user
# approved_approvers is only populated after MR
is merged
has_
and_belongs_to_many
:approved_approvers
,
class_name:
'User'
,
join_table: :approval_merge_request_rules_approved_approvers
has_one
:approval_merge_request_rule_source
has_one
:approval_project_rule
,
through: :approval_merge_request_rule_source
...
...
@@ -31,10 +31,10 @@ class ApprovalMergeRequestRule < ApplicationRecord
scope
end
def
sync_approv
al
s
# Before being merged, approv
als are dynamically calculated
instead of being persisted.
def
sync_approv
ed_approver
s
# Before being merged, approv
ed_approvers are dynamically calculated in ApprovalWrappedRule
instead of being persisted.
return
unless
merge_request
.
merged?
self
.
approv
als
=
merge_request
.
approvals
.
where
(
user_id:
approvers
.
map
(
&
:id
)
)
self
.
approv
ed_approver_ids
=
merge_request
.
approvals
.
map
(
&
:user_id
)
&
approvers
.
map
(
&
:id
)
end
end
ee/app/services/approval_rules/finalize_service.rb
View file @
7f80b6ed
...
...
@@ -17,7 +17,7 @@ module ApprovalRules
copy_project_approval_rules
end
merge_request
.
approval_rules
.
each
(
&
:sync_approv
al
s
)
merge_request
.
approval_rules
.
each
(
&
:sync_approv
ed_approver
s
)
end
private
...
...
ee/db/migrate/20181204031329_create_approval_rules_approvals.rb
View file @
7f80b6ed
...
...
@@ -6,7 +6,7 @@ class CreateApprovalRulesApprovals < ActiveRecord::Migration[5.0]
DOWNTIME
=
false
def
change
create_table
(
:approval_merge_request_rules_approv
al
s
,
id: :bigserial
)
do
|
t
|
create_table
(
:approval_merge_request_rules_approv
ed_approver
s
,
id: :bigserial
)
do
|
t
|
t
.
references
(
:approval_merge_request_rule
,
type: :bigint
,
...
...
@@ -15,14 +15,14 @@ class CreateApprovalRulesApprovals < ActiveRecord::Migration[5.0]
index:
false
)
t
.
references
(
:
approval
,
:
user
,
type: :integer
,
null:
false
,
foreign_key:
{
on_delete: :cascade
},
index:
{
name:
'index_approval_merge_request_rules_approv
al
s_2'
}
index:
{
name:
'index_approval_merge_request_rules_approv
ed_approver
s_2'
}
)
t
.
index
[
:approval_merge_request_rule_id
,
:
approval_id
],
unique:
true
,
name:
'index_approval_merge_request_rules_approval
s_1'
t
.
index
[
:approval_merge_request_rule_id
,
:
user_id
],
unique:
true
,
name:
'index_approval_merge_request_rules_approved_approver
s_1'
end
end
end
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
7f80b6ed
...
...
@@ -30,7 +30,7 @@ RSpec.describe ApprovalMergeRequestRule, type: :model do
end
end
describe
'#sync_approv
al
s'
do
describe
'#sync_approv
ed_approver
s'
do
let
(
:member1
)
{
create
(
:user
)
}
let
(
:member2
)
{
create
(
:user
)
}
let
(
:member3
)
{
create
(
:user
)
}
...
...
@@ -44,9 +44,9 @@ RSpec.describe ApprovalMergeRequestRule, type: :model do
context
'when not merged'
do
it
'does nothing'
do
subject
.
sync_approv
al
s
subject
.
sync_approv
ed_approver
s
expect
(
subject
.
approv
al
s
).
to
be_empty
expect
(
subject
.
approv
ed_approver
s
).
to
be_empty
end
end
...
...
@@ -54,9 +54,9 @@ RSpec.describe ApprovalMergeRequestRule, type: :model do
let
(
:merge_request
)
{
create
(
:merged_merge_request
)
}
it
'updates mapping'
do
subject
.
sync_approv
al
s
subject
.
sync_approv
ed_approver
s
expect
(
subject
.
approv
als
.
reload
).
to
contain_exactly
(
approval1
,
approval
2
)
expect
(
subject
.
approv
ed_approvers
.
reload
).
to
contain_exactly
(
member1
,
member
2
)
end
end
end
...
...
ee/spec/services/approval_rules/finalize_service_spec.rb
View file @
7f80b6ed
...
...
@@ -35,11 +35,6 @@ describe ApprovalRules::FinalizeService do
expect
do
subject
.
execute
end
.
not_to
change
{
ApprovalMergeRequestRule
.
count
}
expect
(
approval1
.
approval_rules
).
to
be_empty
expect
(
approval2
.
approval_rules
).
to
be_empty
expect
(
approval3
.
approval_rules
).
to
be_empty
expect
(
approval4
.
approval_rules
).
to
be_empty
end
end
...
...
@@ -64,10 +59,8 @@ describe ApprovalRules::FinalizeService do
expect
(
rule
.
approvals_required
).
to
eq
(
12
)
expect
(
rule
.
users
).
to
contain_exactly
(
member1
,
member2
,
group1_member
)
expect
(
rule
.
groups
).
to
contain_exactly
(
group1
)
expect
(
approval1
.
approval_rules
).
to
contain_exactly
(
rule
)
expect
(
approval2
.
approval_rules
).
to
be_empty
expect
(
approval3
.
approval_rules
).
to
contain_exactly
(
rule
)
expect
(
approval4
.
approval_rules
).
to
be_empty
expect
(
rule
.
approved_approvers
).
to
contain_exactly
(
member1
,
group1_member
)
end
end
end
...
...
@@ -97,10 +90,8 @@ describe ApprovalRules::FinalizeService do
expect
(
rule
.
approvals_required
).
to
eq
(
32
)
expect
(
rule
.
users
).
to
contain_exactly
(
member2
,
member3
,
group2_member
)
expect
(
rule
.
groups
).
to
contain_exactly
(
group2
)
expect
(
approval1
.
approval_rules
).
to
be_empty
expect
(
approval2
.
approval_rules
).
to
contain_exactly
(
rule
)
expect
(
approval3
.
approval_rules
).
to
be_empty
expect
(
approval4
.
approval_rules
).
to
contain_exactly
(
rule
)
expect
(
rule
.
approved_approvers
).
to
contain_exactly
(
member3
,
group2_member
)
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