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
e3716f67
Commit
e3716f67
authored
May 25, 2020
by
Kerri Miller
Committed by
Thong Kuah
May 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add section when creating a codeowners rule
parent
7a998d4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
14 deletions
+24
-14
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+1
-0
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+23
-14
No files found.
ee/app/models/approval_merge_request_rule.rb
View file @
e3716f67
...
@@ -67,6 +67,7 @@ class ApprovalMergeRequestRule < ApplicationRecord
...
@@ -67,6 +67,7 @@ class ApprovalMergeRequestRule < ApplicationRecord
def
self
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)
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
|
merge_request
.
approval_rules
.
code_owner
.
where
(
name:
entry
.
pattern
).
first_or_create
do
|
rule
|
rule
.
section
=
entry
.
section
rule
.
rule_type
=
:code_owner
rule
.
rule_type
=
:code_owner
rule
.
code_owner
=
true
# deprecated, replaced with `rule_type: :code_owner`
rule
.
code_owner
=
true
# deprecated, replaced with `rule_type: :code_owner`
end
end
...
...
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
e3716f67
...
@@ -155,29 +155,32 @@ describe ApprovalMergeRequestRule do
...
@@ -155,29 +155,32 @@ describe ApprovalMergeRequestRule do
end
end
describe
'.find_or_create_code_owner_rule'
do
describe
'.find_or_create_code_owner_rule'
do
let!
(
:existing_code_owner_rule
)
{
create
(
:code_owner_rule
,
name:
'*.rb'
,
merge_request:
merge_request
)
}
subject
(
:rule
)
{
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)
}
it
'finds an existing rule'
do
let
(
:entry
)
{
Gitlab
::
CodeOwners
::
Entry
.
new
(
"*.js"
,
"@user"
)
}
entry
=
Gitlab
::
CodeOwners
::
Entry
.
new
(
"*.rb"
,
"@user"
)
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
))
context
"when there is an existing rule"
do
.
to
eq
(
existing_code_owner_rule
)
let!
(
:existing_code_owner_rule
)
do
create
(
:code_owner_rule
,
name:
'*.rb'
,
merge_request:
merge_request
)
end
let
(
:entry
)
{
Gitlab
::
CodeOwners
::
Entry
.
new
(
"*.rb"
,
"@user"
)
}
it
'finds the existing rule'
do
expect
(
rule
).
to
eq
(
existing_code_owner_rule
)
end
end
end
it
'creates a new rule if it does not exist'
do
it
'creates a new rule if it does not exist'
do
entry
=
Gitlab
::
CodeOwners
::
Entry
.
new
(
"*.js"
,
"@user"
)
expect
{
rule
}
expect
{
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)
}
.
to
change
{
merge_request
.
approval_rules
.
matching_pattern
(
'*.js'
).
count
}.
by
(
1
)
.
to
change
{
merge_request
.
approval_rules
.
matching_pattern
(
'*.js'
).
count
}.
by
(
1
)
end
end
it
'finds an existing rule using deprecated code_owner column'
do
it
'finds an existing rule using deprecated code_owner column'
do
deprecated_code_owner_rule
=
create
(
:code_owner_rule
,
name:
'*.
md
'
,
merge_request:
merge_request
)
deprecated_code_owner_rule
=
create
(
:code_owner_rule
,
name:
'*.
js
'
,
merge_request:
merge_request
)
deprecated_code_owner_rule
.
update_column
(
:rule_type
,
described_class
.
rule_types
[
:regular
])
deprecated_code_owner_rule
.
update_column
(
:rule_type
,
described_class
.
rule_types
[
:regular
])
entry
=
Gitlab
::
CodeOwners
::
Entry
.
new
(
"*.md"
,
"@user"
)
expect
(
rule
)
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
))
.
to
eq
(
deprecated_code_owner_rule
)
.
to
eq
(
deprecated_code_owner_rule
)
end
end
...
@@ -185,9 +188,15 @@ describe ApprovalMergeRequestRule do
...
@@ -185,9 +188,15 @@ describe ApprovalMergeRequestRule do
expect
(
described_class
).
to
receive
(
:code_owner
).
and_raise
(
ActiveRecord
::
RecordNotUnique
)
expect
(
described_class
).
to
receive
(
:code_owner
).
and_raise
(
ActiveRecord
::
RecordNotUnique
)
allow
(
described_class
).
to
receive
(
:code_owner
).
and_call_original
allow
(
described_class
).
to
receive
(
:code_owner
).
and_call_original
entry
=
Gitlab
::
CodeOwners
::
Entry
.
new
(
"*.js"
,
"@user"
)
expect
(
rule
).
not_to
be_nil
end
expect
(
described_class
.
find_or_create_code_owner_rule
(
merge_request
,
entry
)).
not_to
be_nil
context
"when section is present"
do
let
(
:entry
)
{
Gitlab
::
CodeOwners
::
Entry
.
new
(
"*.js"
,
"@user"
,
"Test Section"
)
}
it
"creates a new rule and saves section when present"
do
expect
(
subject
.
section
).
to
eq
(
entry
.
section
)
end
end
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