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
45fc8b73
Commit
45fc8b73
authored
Sep 09, 2016
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix API issues sorting
parent
b7e6da5a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
9 deletions
+130
-9
CHANGELOG
CHANGELOG
+1
-0
lib/api/issues.rb
lib/api/issues.rb
+9
-3
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+120
-6
No files found.
CHANGELOG
View file @
45fc8b73
...
...
@@ -15,6 +15,7 @@ v 8.12.0 (unreleased)
- Change logo animation to CSS (ClemMakesApps)
- Instructions for enabling Git packfile bitmaps !6104
- Fix pagination on user snippets page
- Fix sorting of issues in API
- Escape search term before passing it to Regexp.new !6241 (winniehell)
- Fix pinned sidebar behavior in smaller viewports !6169
- Change merge_error column from string to text type
...
...
lib/api/issues.rb
View file @
45fc8b73
...
...
@@ -41,7 +41,8 @@ module API
issues
=
current_user
.
issues
.
inc_notes_with_associations
issues
=
filter_issues_state
(
issues
,
params
[
:state
])
unless
params
[
:state
].
nil?
issues
=
filter_issues_labels
(
issues
,
params
[
:labels
])
unless
params
[
:labels
].
nil?
issues
.
reorder
(
issuable_order_by
=>
issuable_sort
)
issues
=
issues
.
reorder
(
issuable_order_by
=>
issuable_sort
)
present
paginate
(
issues
),
with:
Entities
::
Issue
,
current_user:
current_user
end
end
...
...
@@ -73,7 +74,11 @@ module API
params
[
:group_id
]
=
group
.
id
params
[
:milestone_title
]
=
params
.
delete
(
:milestone
)
params
[
:label_name
]
=
params
.
delete
(
:labels
)
params
[
:sort
]
=
"
#{
params
.
delete
(
:order_by
)
}
_
#{
params
.
delete
(
:sort
)
}
"
if
params
[
:order_by
]
&&
params
[
:sort
]
if
params
[
:order_by
]
||
params
[
:sort
]
# The Sortable concern takes 'created_desc', not 'created_at_desc' (for example)
params
[
:sort
]
=
"
#{
issuable_order_by
.
sub
(
'_at'
,
''
)
}
_
#{
issuable_sort
}
"
end
issues
=
IssuesFinder
.
new
(
current_user
,
params
).
execute
...
...
@@ -113,7 +118,8 @@ module API
issues
=
filter_issues_milestone
(
issues
,
params
[
:milestone
])
end
issues
.
reorder
(
issuable_order_by
=>
issuable_sort
)
issues
=
issues
.
reorder
(
issuable_order_by
=>
issuable_sort
)
present
paginate
(
issues
),
with:
Entities
::
Issue
,
current_user:
current_user
end
...
...
spec/requests/api/issues_spec.rb
View file @
45fc8b73
...
...
@@ -17,21 +17,24 @@ describe API::API, api: true do
assignee:
user
,
project:
project
,
state: :closed
,
milestone:
milestone
milestone:
milestone
,
updated_at:
3
.
hours
.
ago
end
let!
(
:confidential_issue
)
do
create
:issue
,
:confidential
,
project:
project
,
author:
author
,
assignee:
assignee
assignee:
assignee
,
updated_at:
2
.
hours
.
ago
end
let!
(
:issue
)
do
create
:issue
,
author:
user
,
assignee:
user
,
project:
project
,
milestone:
milestone
milestone:
milestone
,
updated_at:
1
.
hour
.
ago
end
let!
(
:label
)
do
create
(
:label
,
title:
'label'
,
color:
'#FFAABB'
,
project:
project
)
...
...
@@ -135,6 +138,42 @@ describe API::API, api: true do
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
it
'sorts by created_at descending by default'
do
get
api
(
'/issues'
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'created_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts ascending when requested'
do
get
api
(
'/issues?sort=asc'
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'created_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
it
'sorts by updated_at descending when requested'
do
get
api
(
'/issues?order_by=updated_at'
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'updated_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by updated_at ascending when requested'
do
get
api
(
'/issues?order_by=updated_at&sort=asc'
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'updated_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
end
end
...
...
@@ -147,21 +186,24 @@ describe API::API, api: true do
assignee:
user
,
project:
group_project
,
state: :closed
,
milestone:
group_milestone
milestone:
group_milestone
,
updated_at:
3
.
hours
.
ago
end
let!
(
:group_confidential_issue
)
do
create
:issue
,
:confidential
,
project:
group_project
,
author:
author
,
assignee:
assignee
assignee:
assignee
,
updated_at:
2
.
hours
.
ago
end
let!
(
:group_issue
)
do
create
:issue
,
author:
user
,
assignee:
user
,
project:
group_project
,
milestone:
group_milestone
milestone:
group_milestone
,
updated_at:
1
.
hour
.
ago
end
let!
(
:group_label
)
do
create
(
:label
,
title:
'group_lbl'
,
color:
'#FFAABB'
,
project:
group_project
)
...
...
@@ -278,6 +320,42 @@ describe API::API, api: true do
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
group_closed_issue
.
id
)
end
it
'sorts by created_at descending by default'
do
get
api
(
base_url
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'created_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts ascending when requested'
do
get
api
(
"
#{
base_url
}
?sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'created_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
it
'sorts by updated_at descending when requested'
do
get
api
(
"
#{
base_url
}
?order_by=updated_at"
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'updated_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by updated_at ascending when requested'
do
get
api
(
"
#{
base_url
}
?order_by=updated_at&sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'updated_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
end
describe
"GET /projects/:id/issues"
do
...
...
@@ -386,6 +464,42 @@ describe API::API, api: true do
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
closed_issue
.
id
)
end
it
'sorts by created_at descending by default'
do
get
api
(
"
#{
base_url
}
/issues"
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'created_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts ascending when requested'
do
get
api
(
"
#{
base_url
}
/issues?sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'created_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
it
'sorts by updated_at descending when requested'
do
get
api
(
"
#{
base_url
}
/issues?order_by=updated_at"
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'updated_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by updated_at ascending when requested'
do
get
api
(
"
#{
base_url
}
/issues?order_by=updated_at&sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
issue
|
issue
[
'updated_at'
]
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
end
describe
"GET /projects/:id/issues/:issue_id"
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