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
034d2e4e
Commit
034d2e4e
authored
Jan 04, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'api-refactor-issues-filter' into 'master'
Refactor issues filter in API See merge request !8432
parents
cad8724e
0199f186
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
21 deletions
+8
-21
lib/api/issues.rb
lib/api/issues.rb
+8
-21
No files found.
lib/api/issues.rb
View file @
034d2e4e
...
@@ -5,28 +5,18 @@ module API
...
@@ -5,28 +5,18 @@ module API
before
{
authenticate!
}
before
{
authenticate!
}
helpers
do
helpers
do
def
filter_issues_state
(
issues
,
state
)
# TODO: Remove in 9.0 and switch to IssueFinder-based label filtering
case
state
when
'opened'
then
issues
.
opened
when
'closed'
then
issues
.
closed
else
issues
end
end
def
filter_issues_labels
(
issues
,
labels
)
def
filter_issues_labels
(
issues
,
labels
)
issues
.
includes
(
:labels
).
where
(
'labels.title'
=>
labels
.
split
(
','
))
issues
.
includes
(
:labels
).
where
(
'labels.title'
=>
labels
.
split
(
','
))
end
end
def
filter_issues_milestone
(
issues
,
milestone
)
issues
.
includes
(
:milestone
).
where
(
'milestones.title'
=>
milestone
)
end
params
:issues_params
do
params
:issues_params
do
optional
:labels
,
type:
String
,
desc:
'Comma-separated list of label names'
optional
:labels
,
type:
String
,
desc:
'Comma-separated list of label names'
optional
:order_by
,
type:
String
,
values:
%w[created_at updated_at]
,
default:
'created_at'
,
optional
:order_by
,
type:
String
,
values:
%w[created_at updated_at]
,
default:
'created_at'
,
desc:
'Return issues ordered by `created_at` or `updated_at` fields.'
desc:
'Return issues ordered by `created_at` or `updated_at` fields.'
optional
:sort
,
type:
String
,
values:
%w[asc desc]
,
default:
'desc'
,
optional
:sort
,
type:
String
,
values:
%w[asc desc]
,
default:
'desc'
,
desc:
'Return issues sorted in `asc` or `desc` order.'
desc:
'Return issues sorted in `asc` or `desc` order.'
optional
:milestone
,
type:
String
,
desc:
'Return issues for a specific milestone'
use
:pagination
use
:pagination
end
end
...
@@ -50,8 +40,7 @@ module API
...
@@ -50,8 +40,7 @@ module API
use
:issues_params
use
:issues_params
end
end
get
do
get
do
issues
=
current_user
.
issues
.
inc_notes_with_associations
issues
=
IssuesFinder
.
new
(
current_user
,
scope:
'all'
,
author_id:
current_user
.
id
,
state:
params
[
:state
]).
execute
.
inc_notes_with_associations
issues
=
filter_issues_state
(
issues
,
params
[
:state
])
issues
=
filter_issues_labels
(
issues
,
params
[
:labels
])
unless
params
[
:labels
].
nil?
issues
=
filter_issues_labels
(
issues
,
params
[
:labels
])
unless
params
[
:labels
].
nil?
issues
=
issues
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
issues
=
issues
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
...
@@ -99,16 +88,14 @@ module API
...
@@ -99,16 +88,14 @@ module API
use
:issues_params
use
:issues_params
end
end
get
":id/issues"
do
get
":id/issues"
do
issues
=
IssuesFinder
.
new
(
current_user
,
project_id:
user_project
.
id
).
execute
.
inc_notes_with_associations
issues
=
IssuesFinder
.
new
(
current_user
,
issues
=
filter_issues_state
(
issues
,
params
[
:state
])
project_id:
user_project
.
id
,
state:
params
[
:state
],
milestone_title:
params
[
:milestone
]).
execute
.
inc_notes_with_associations
issues
=
filter_issues_labels
(
issues
,
params
[
:labels
])
unless
params
[
:labels
].
nil?
issues
=
filter_issues_labels
(
issues
,
params
[
:labels
])
unless
params
[
:labels
].
nil?
issues
=
filter_by_iid
(
issues
,
params
[
:iid
])
unless
params
[
:iid
].
nil?
issues
=
filter_by_iid
(
issues
,
params
[
:iid
])
unless
params
[
:iid
].
nil?
unless
params
[
:milestone
].
nil?
issues
=
filter_issues_milestone
(
issues
,
params
[
:milestone
])
end
issues
=
issues
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
issues
=
issues
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
present
paginate
(
issues
),
with:
Entities
::
Issue
,
current_user:
current_user
,
project:
user_project
present
paginate
(
issues
),
with:
Entities
::
Issue
,
current_user:
current_user
,
project:
user_project
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