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
1adabce4
Commit
1adabce4
authored
Apr 21, 2020
by
Kerri Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update accepted params to accept and Entry object
parent
d44d494c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
8 deletions
+17
-8
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+2
-2
ee/app/services/merge_requests/sync_code_owner_approval_rules.rb
...services/merge_requests/sync_code_owner_approval_rules.rb
+1
-1
ee/lib/ee/gitlab/background_migration/migrate_approver_to_approval_rules.rb
...ackground_migration/migrate_approver_to_approval_rules.rb
+1
-1
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+13
-4
No files found.
ee/app/models/approval_merge_request_rule.rb
View file @
1adabce4
...
...
@@ -65,8 +65,8 @@ class ApprovalMergeRequestRule < ApplicationRecord
scope
:open_merge_requests
,
->
{
merge
(
MergeRequest
.
opened
)
}
scope
:for_checks_that_can_be_refreshed
,
->
{
license_compliance
.
open_merge_requests
.
with_head_pipeline
}
def
self
.
find_or_create_code_owner_rule
(
merge_request
,
pattern
)
merge_request
.
approval_rules
.
code_owner
.
where
(
name:
pattern
).
first_or_create
do
|
rule
|
def
self
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)
merge_request
.
approval_rules
.
code_owner
.
where
(
name:
entry
.
pattern
).
first_or_create
do
|
rule
|
rule
.
rule_type
=
:code_owner
rule
.
code_owner
=
true
# deprecated, replaced with `rule_type: :code_owner`
end
...
...
ee/app/services/merge_requests/sync_code_owner_approval_rules.rb
View file @
1adabce4
...
...
@@ -30,7 +30,7 @@ module MergeRequests
attr_reader
:merge_request
,
:previous_diff
def
create_rule
(
entry
)
ApprovalMergeRequestRule
.
find_or_create_code_owner_rule
(
merge_request
,
entry
.
pattern
)
ApprovalMergeRequestRule
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)
end
def
delete_outdated_code_owner_rules
...
...
ee/lib/ee/gitlab/background_migration/migrate_approver_to_approval_rules.rb
View file @
1adabce4
...
...
@@ -130,7 +130,7 @@ module EE
rule
=
approval_rules
.
code_owner
.
first
rule
||=
ApprovalMergeRequestRule
.
find_or_create_code_owner_rule
(
self
,
'Code Owner'
Struct
.
new
(
:pattern
,
:owner_line
).
new
(
"Code Owner"
)
)
rule
.
users
=
owners
.
uniq
...
...
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
1adabce4
...
...
@@ -156,14 +156,19 @@ describe ApprovalMergeRequestRule do
describe
'.find_or_create_code_owner_rule'
do
let!
(
:existing_code_owner_rule
)
{
create
(
:code_owner_rule
,
name:
'*.rb'
,
merge_request:
merge_request
)
}
let
(
:entry
)
{
Struct
.
new
(
:pattern
,
:owner_line
).
new
}
it
'finds an existing rule'
do
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
'*.rb'
))
entry
.
pattern
=
"*.rb"
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
))
.
to
eq
(
existing_code_owner_rule
)
end
it
'creates a new rule if it does not exist'
do
expect
{
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
'*.js'
)
}
entry
.
pattern
=
"*.js"
expect
{
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)
}
.
to
change
{
merge_request
.
approval_rules
.
matching_pattern
(
'*.js'
).
count
}.
by
(
1
)
end
...
...
@@ -171,7 +176,9 @@ describe ApprovalMergeRequestRule do
deprecated_code_owner_rule
=
create
(
:code_owner_rule
,
name:
'*.md'
,
merge_request:
merge_request
)
deprecated_code_owner_rule
.
update_column
(
:rule_type
,
described_class
.
rule_types
[
:regular
])
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
'*.md'
))
entry
.
pattern
=
"*.md"
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
))
.
to
eq
(
deprecated_code_owner_rule
)
end
...
...
@@ -179,7 +186,9 @@ describe ApprovalMergeRequestRule do
expect
(
described_class
).
to
receive
(
:code_owner
).
and_raise
(
ActiveRecord
::
RecordNotUnique
)
allow
(
described_class
).
to
receive
(
:code_owner
).
and_call_original
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
'*.js'
)).
not_to
be_nil
entry
.
pattern
=
"*.js"
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)).
not_to
be_nil
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