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
458e4def
Commit
458e4def
authored
Oct 25, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow fetching owners for MR
parent
e3890a26
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
4 deletions
+96
-4
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+6
-0
ee/lib/gitlab/code_owners.rb
ee/lib/gitlab/code_owners.rb
+15
-0
ee/spec/lib/gitlab/code_owners_spec.rb
ee/spec/lib/gitlab/code_owners_spec.rb
+63
-4
ee/spec/models/merge_request_spec.rb
ee/spec/models/merge_request_spec.rb
+12
-0
No files found.
ee/app/models/ee/merge_request.rb
View file @
458e4def
...
...
@@ -50,5 +50,11 @@ module EE
def
participant_approvers
approval_needed?
?
approvers_left
:
[]
end
def
code_owners
strong_memoize
(
:code_owners
)
do
::
Gitlab
::
CodeOwners
.
for_merge_request
(
self
).
freeze
end
end
end
end
ee/lib/gitlab/code_owners.rb
View file @
458e4def
...
...
@@ -12,5 +12,20 @@ module Gitlab
User
.
none
end
end
# @param merge_request [MergeRequest]
# @param merge_request_diff [MergeRequestDiff]
# Find code owners at a particular MergeRequestDiff.
# Assumed to be the most recent one if not provided.
def
self
.
for_merge_request
(
merge_request
,
merge_request_diff:
nil
)
return
[]
if
merge_request
.
source_project
.
nil?
||
merge_request
.
source_branch
.
nil?
return
[]
unless
merge_request
.
target_project
.
feature_available?
(
:code_owners
)
Loader
.
new
(
merge_request
.
target_project
,
merge_request
.
target_branch
,
merge_request
.
modified_paths
(
past_merge_request_diff:
merge_request_diff
)
).
members
.
where_not_in
(
merge_request
.
author
).
to_a
end
end
end
ee/spec/lib/gitlab/code_owners_spec.rb
View file @
458e4def
...
...
@@ -7,18 +7,22 @@ describe Gitlab::CodeOwners do
let!
(
:code_owner
)
{
create
(
:user
,
username:
'owner-1'
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:blob
)
do
project
.
repository
.
blob_at
(
TestEnv
::
BRANCH_SHA
[
'with-codeowners'
],
'docs/CODEOWNERS'
)
end
let
(
:codeowner_content
)
{
"docs/CODEOWNERS @owner-1"
}
let
(
:codeowner_blob
)
{
fake_blob
(
path:
'CODEOWNERS'
,
data:
codeowner_content
)
}
let
(
:codeowner_blob_ref
)
{
fake_blob
(
path:
'CODEOWNERS'
,
data:
codeowner_content
)
}
before
do
project
.
add_developer
(
code_owner
)
allow
(
project
.
repository
).
to
receive
(
:code_owners_blob
).
and_return
(
codeowner_blob
)
allow
(
project
.
repository
).
to
receive
(
:code_owners_blob
)
.
with
(
ref:
codeowner_lookup_ref
)
.
and_return
(
codeowner_blob
)
end
describe
'.for_blob'
do
let
(
:branch
)
{
TestEnv
::
BRANCH_SHA
[
'with-codeowners'
]
}
let
(
:blob
)
{
project
.
repository
.
blob_at
(
branch
,
'docs/CODEOWNERS'
)
}
let
(
:codeowner_lookup_ref
)
{
branch
}
context
'when the feature is available'
do
before
do
stub_licensed_features
(
code_owners:
true
)
...
...
@@ -39,4 +43,59 @@ describe Gitlab::CodeOwners do
end
end
end
describe
'.for_merge_request'
do
let
(
:codeowner_lookup_ref
)
{
merge_request
.
target_branch
}
let
(
:merge_request
)
do
build
(
:merge_request
,
source_project:
project
,
source_branch:
'feature'
,
target_project:
project
,
target_branch:
'with-codeowners'
)
end
context
'when the feature is available'
do
before
do
stub_licensed_features
(
code_owners:
true
)
end
it
'returns owners for merge request'
do
expect
(
merge_request
).
to
receive
(
:modified_paths
).
with
(
past_merge_request_diff:
nil
).
and_return
([
'docs/CODEOWNERS'
])
expect
(
described_class
.
for_merge_request
(
merge_request
)).
to
eq
([
code_owner
])
end
context
'when owner is merge request author'
do
let
(
:merge_request
)
{
build
(
:merge_request
,
target_project:
project
,
author:
code_owner
)
}
it
'excludes author'
do
expect
(
merge_request
).
to
receive
(
:modified_paths
).
with
(
past_merge_request_diff:
nil
).
and_return
([
'docs/CODEOWNERS'
])
expect
(
described_class
.
for_merge_request
(
merge_request
)).
to
eq
([])
end
end
context
'when merge_request_diff is specified'
do
let
(
:merge_request_diff
)
{
double
(
:merge_request_diff
)
}
it
'returns owners at the specified ref'
do
expect
(
merge_request
).
to
receive
(
:modified_paths
).
with
(
past_merge_request_diff:
merge_request_diff
).
and_return
([
'docs/CODEOWNERS'
])
expect
(
described_class
.
for_merge_request
(
merge_request
,
merge_request_diff:
merge_request_diff
)).
to
eq
([
code_owner
])
end
end
end
context
'when the feature is not available'
do
before
do
stub_licensed_features
(
code_owners:
false
)
end
it
'returns no users'
do
expect
(
described_class
.
for_merge_request
(
merge_request
)).
to
eq
([])
end
end
end
end
ee/spec/models/merge_request_spec.rb
View file @
458e4def
...
...
@@ -14,6 +14,18 @@ describe MergeRequest do
it
{
is_expected
.
to
have_many
(
:approved_by_users
)
}
end
describe
'#code_owners'
do
subject
(
:merge_request
)
{
build
(
:merge_request
)
}
let
(
:owners
)
{
[
double
(
:owner
)]
}
it
'returns code owners, frozen'
do
allow
(
::
Gitlab
::
CodeOwners
).
to
receive
(
:for_merge_request
).
with
(
subject
).
and_return
(
owners
)
expect
(
subject
.
code_owners
).
to
eq
(
owners
)
expect
(
subject
.
code_owners
).
to
be_frozen
end
end
describe
'#approvals_before_merge'
do
where
(
:license_value
,
:db_value
,
:expected
)
do
true
|
5
|
5
...
...
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