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
65723a2c
Commit
65723a2c
authored
Jan 25, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify MergeRequestsFinder to allow filtering by commit
parent
276147c1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
4 deletions
+45
-4
app/controllers/projects/commit_controller.rb
app/controllers/projects/commit_controller.rb
+5
-1
app/finders/merge_requests_finder.rb
app/finders/merge_requests_finder.rb
+8
-1
lib/api/commits.rb
lib/api/commits.rb
+7
-1
spec/finders/merge_requests_finder_spec.rb
spec/finders/merge_requests_finder_spec.rb
+25
-1
No files found.
app/controllers/projects/commit_controller.rb
View file @
65723a2c
...
...
@@ -65,7 +65,11 @@ class Projects::CommitController < Projects::ApplicationController
# rubocop: enable CodeReuse/ActiveRecord
def
merge_requests
@merge_requests
=
@commit
.
merge_requests
.
map
do
|
mr
|
@merge_requests
=
MergeRequestsFinder
.
new
(
current_user
,
project_id:
@project
.
id
,
commit_sha:
@commit
.
sha
).
execute
.
map
do
|
mr
|
{
iid:
mr
.
iid
,
path:
merge_request_path
(
mr
),
title:
mr
.
title
}
end
...
...
app/finders/merge_requests_finder.rb
View file @
65723a2c
...
...
@@ -36,13 +36,20 @@ class MergeRequestsFinder < IssuableFinder
end
def
filter_items
(
_items
)
items
=
by_source_branch
(
super
)
items
=
by_commit
(
super
)
items
=
by_source_branch
(
items
)
items
=
by_wip
(
items
)
by_target_branch
(
items
)
end
private
def
by_commit
(
items
)
return
items
unless
params
[
:commit_sha
].
presence
items
.
by_commit_sha
(
params
[
:commit_sha
])
end
def
source_branch
@source_branch
||=
params
[
:source_branch
].
presence
end
...
...
lib/api/commits.rb
View file @
65723a2c
...
...
@@ -323,7 +323,13 @@ module API
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
present
paginate
(
commit
.
merge_requests
),
with:
Entities
::
MergeRequestBasic
commit_merge_requests
=
MergeRequestsFinder
.
new
(
current_user
,
project_id:
user_project
.
id
,
commit_sha:
commit
.
sha
).
execute
present
paginate
(
commit_merge_requests
),
with:
Entities
::
MergeRequestBasic
end
end
end
...
...
spec/finders/merge_requests_finder_spec.rb
View file @
65723a2c
...
...
@@ -31,7 +31,7 @@ describe MergeRequestsFinder do
p
end
end
let
(
:project4
)
{
create_project_without_n_plus_1
(
group:
subgroup
)
}
let
(
:project4
)
{
create_project_without_n_plus_1
(
:repository
,
group:
subgroup
)
}
let
(
:project5
)
{
create_project_without_n_plus_1
(
group:
subgroup
)
}
let
(
:project6
)
{
create_project_without_n_plus_1
(
group:
subgroup
)
}
...
...
@@ -68,6 +68,15 @@ describe MergeRequestsFinder do
expect
(
merge_requests
.
size
).
to
eq
(
2
)
end
it
'filters by commit sha'
do
merge_requests
=
described_class
.
new
(
user
,
commit_sha:
merge_request5
.
merge_request_diff
.
last_commit_sha
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
merge_request5
)
end
context
'filtering by group'
do
it
'includes all merge requests when user has access'
do
params
=
{
group_id:
group
.
id
}
...
...
@@ -269,6 +278,21 @@ describe MergeRequestsFinder do
expect
(
merge_requests
).
to
contain_exactly
(
old_merge_request
,
new_merge_request
)
end
end
context
'when project restricts merge requests'
do
let
(
:non_member
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
,
:merge_requests_private
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
it
"returns nothing to to non members"
do
merge_requests
=
described_class
.
new
(
non_member
,
project_id:
project
.
id
).
execute
expect
(
merge_requests
).
to
be_empty
end
end
end
describe
'#row_count'
,
:request_store
do
...
...
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