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
0851f67a
Commit
0851f67a
authored
Jul 03, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter by draft merge requests
We can mark WIP merge requests as Draft and should be able to filter by them
parent
7d532353
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
28 deletions
+64
-28
app/finders/merge_requests_finder.rb
app/finders/merge_requests_finder.rb
+18
-6
spec/finders/merge_requests_finder_spec.rb
spec/finders/merge_requests_finder_spec.rb
+46
-22
No files found.
app/finders/merge_requests_finder.rb
View file @
0851f67a
...
...
@@ -31,7 +31,7 @@
#
class
MergeRequestsFinder
<
IssuableFinder
def
self
.
scalar_params
@scalar_params
||=
super
+
[
:wip
,
:target_branch
]
@scalar_params
||=
super
+
[
:wip
,
:
draft
,
:
target_branch
]
end
def
klass
...
...
@@ -42,7 +42,7 @@ class MergeRequestsFinder < IssuableFinder
items
=
by_commit
(
super
)
items
=
by_deployment
(
items
)
items
=
by_source_branch
(
items
)
items
=
by_
wip
(
items
)
items
=
by_
draft
(
items
)
items
=
by_target_branch
(
items
)
by_source_project_id
(
items
)
end
...
...
@@ -88,20 +88,32 @@ class MergeRequestsFinder < IssuableFinder
items
.
where
(
source_project_id:
source_project_id
)
end
def
by_wip
(
items
)
if
params
[
:wip
]
==
'yes'
def
by_draft
(
items
)
draft_param
=
params
[
:draft
]
||
params
[
:wip
]
if
draft_param
==
'yes'
items
.
where
(
wip_match
(
items
.
arel_table
))
elsif
params
[
:wip
]
==
'no'
elsif
draft_param
==
'no'
items
.
where
.
not
(
wip_match
(
items
.
arel_table
))
else
items
end
end
# WIP is deprecated in favor of Draft. Currently both options are supported
def
wip_match
(
table
)
table
[
:title
].
matches
(
'WIP:%'
)
items
=
table
[
:title
].
matches
(
'WIP:%'
)
.
or
(
table
[
:title
].
matches
(
'WIP %'
))
.
or
(
table
[
:title
].
matches
(
'[WIP]%'
))
return
items
unless
Feature
.
enabled?
(
:merge_request_draft_filter
)
items
.
or
(
table
[
:title
].
matches
(
'Draft - %'
))
.
or
(
table
[
:title
].
matches
(
'Draft:%'
))
.
or
(
table
[
:title
].
matches
(
'[Draft]%'
))
.
or
(
table
[
:title
].
matches
(
'(Draft)%'
))
end
def
by_deployment
(
items
)
...
...
spec/finders/merge_requests_finder_spec.rb
View file @
0851f67a
...
...
@@ -192,43 +192,59 @@ RSpec.describe MergeRequestsFinder do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request3
)
end
describe
'
WIP
state'
do
describe
'
draft
state'
do
let!
(
:wip_merge_request1
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project5
,
target_project:
project5
,
title:
'WIP: thing'
)
}
let!
(
:wip_merge_request2
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project6
,
target_project:
project6
,
title:
'wip thing'
)
}
let!
(
:wip_merge_request3
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project1
,
target_project:
project1
,
title:
'[wip] thing'
)
}
let!
(
:wip_merge_request4
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project1
,
target_project:
project2
,
title:
'wip: thing'
)
}
let!
(
:draft_merge_request1
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_branch:
'draft1'
,
source_project:
project5
,
target_project:
project5
,
title:
'Draft: thing'
)
}
let!
(
:draft_merge_request2
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_branch:
'draft2'
,
source_project:
project6
,
target_project:
project6
,
title:
'[draft] thing'
)
}
let!
(
:draft_merge_request3
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_branch:
'draft3'
,
source_project:
project1
,
target_project:
project1
,
title:
'(draft) thing'
)
}
let!
(
:draft_merge_request4
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_branch:
'draft4'
,
source_project:
project1
,
target_project:
project2
,
title:
'Draft - thing'
)
}
it
'filters by wip'
do
params
=
{
wip:
'yes'
}
[
:wip
,
:draft
].
each
do
|
draft_param_key
|
it
"filters by
#{
draft_param_key
}
"
do
params
=
{
draft_param_key
=>
'yes'
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
merge_request4
,
merge_request5
,
wip_merge_request1
,
wip_merge_request2
,
wip_merge_request3
,
wip_merge_request4
)
end
expect
(
merge_requests
).
to
contain_exactly
(
merge_request4
,
merge_request5
,
wip_merge_request1
,
wip_merge_request2
,
wip_merge_request3
,
wip_merge_request4
,
draft_merge_request1
,
draft_merge_request2
,
draft_merge_request3
,
draft_merge_request4
)
end
it
'filters by not wip'
do
params
=
{
wip:
'no'
}
context
'when merge_request_draft_filter is disabled'
do
it
'does not include draft merge requests'
do
stub_feature_flags
(
merge_request_draft_filter:
false
)
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
{
draft_param_key
=>
'yes'
}
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
)
end
expect
(
merge_requests
).
to
contain_exactly
(
merge_request4
,
merge_request5
,
wip_merge_request1
,
wip_merge_request2
,
wip_merge_request3
,
wip_merge_request4
)
end
end
it
'returns all items if no valid wip param exists'
do
params
=
{
wip:
'
'
}
it
"filters by not
#{
draft_param_key
}
"
do
params
=
{
draft_param_key
=>
'no
'
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
,
merge_request4
,
merge_request5
,
wip_merge_request1
,
wip_merge_request2
,
wip_merge_request3
,
wip_merge_request4
)
end
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
)
end
it
'adds wip to scalar params'
do
scalar_params
=
described_class
.
scalar_params
it
"returns all items if no valid
#{
draft_param_key
}
param exists"
do
params
=
{
draft_param_key
=>
''
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
scalar_params
).
to
include
(
:wip
,
:assignee_id
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
,
merge_request4
,
merge_request5
,
wip_merge_request1
,
wip_merge_request2
,
wip_merge_request3
,
wip_merge_request4
,
draft_merge_request1
,
draft_merge_request2
,
draft_merge_request3
,
draft_merge_request4
)
end
end
context
'filter by deployment'
do
...
...
@@ -265,6 +281,14 @@ RSpec.describe MergeRequestsFinder do
end
end
describe
'.scalar_params'
do
it
'contains scalar params related to merge requests'
do
scalar_params
=
described_class
.
scalar_params
expect
(
scalar_params
).
to
include
(
:wip
,
:draft
,
:assignee_id
)
end
end
context
'assignee filtering'
do
let
(
:issuables
)
{
described_class
.
new
(
user
,
params
).
execute
}
...
...
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