BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b99b2e60
Commit
b99b2e60
authored
Sep 09, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ordering and sorting for MR in api.
parent
09b23228
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
0 deletions
+49
-0
CHANGELOG
CHANGELOG
+1
-0
merge_requests.md
doc/api/merge_requests.md
+2
-0
merge_requests.rb
lib/api/merge_requests.rb
+14
-0
merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+32
-0
No files found.
CHANGELOG
View file @
b99b2e60
...
...
@@ -29,6 +29,7 @@ v 7.3.0
- Enabled Shibboleth authentication support (Matus Banas)
- Zen mode (fullscreen) for issues/MR/notes (Robert Schilling)
- Add ability to configure webhook timeout via gitlab.yml (Wes Gurney)
- Sort project merge requests in asc or desc order for updated_at or created_at field (sponsored by O'Reilly Media)
v 7.2.1
- Delete orphaned labels during label migration (James Brooks)
...
...
doc/api/merge_requests.md
View file @
b99b2e60
...
...
@@ -14,6 +14,8 @@ Parameters:
-
`id`
(required) - The ID of a project
-
`state`
(optional) - Return
`all`
requests or just those that are
`merged`
,
`opened`
or
`closed`
-
`order_by`
(optional) - Return requests ordered by
`created_at`
or
`updated_at`
fields
-
`sort`
(optional) - Return requests sorted in
`asc`
or
`desc`
order
```
json
[
...
...
lib/api/merge_requests.rb
View file @
b99b2e60
...
...
@@ -25,6 +25,10 @@ module API
# GET /projects/:id/merge_requests
# GET /projects/:id/merge_requests?state=opened
# GET /projects/:id/merge_requests?state=closed
# GET /projects/:id/merge_requests?order_by=created_at
# GET /projects/:id/merge_requests?order_by=created_at
# GET /projects/:id/merge_requests?sort=desc
# GET /projects/:id/merge_requests?sort=asc
#
get
":id/merge_requests"
do
authorize!
:read_merge_request
,
user_project
...
...
@@ -36,6 +40,16 @@ module API
else
user_project
.
merge_requests
end
sort
=
case
params
[
"sort"
]
when
'desc'
then
'DESC'
else
'ASC'
end
mrs
=
case
params
[
"order_by"
]
when
'updated_at'
then
mrs
.
order
(
"updated_at
#{
sort
}
"
)
else
mrs
.
order
(
"created_at
#{
sort
}
"
)
end
present
paginate
(
mrs
),
with:
Entities
::
MergeRequest
end
...
...
spec/requests/api/merge_requests_spec.rb
View file @
b99b2e60
...
...
@@ -57,6 +57,38 @@ describe API::API, api: true do
json_response
.
length
.
should
==
1
json_response
.
first
[
'title'
].
should
==
merge_request_merged
.
title
end
it
"should return an array of merge_requests in ascending order"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?sort=asc"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
3
json_response
.
first
[
'id'
].
should
==
merge_request
.
id
json_response
.
last
[
'id'
].
should
==
merge_request_merged
.
id
end
it
"should return an array of merge_requests in descending order"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?sort=desc"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
3
json_response
.
first
[
'id'
].
should
==
merge_request_merged
.
id
json_response
.
last
[
'id'
].
should
==
merge_request
.
id
end
it
"should return an array of merge_requests ordered by updated_at"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?order_by=updated_at"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
3
json_response
.
first
[
'id'
].
should
==
merge_request
.
id
json_response
.
last
[
'id'
].
should
==
merge_request_merged
.
id
end
it
"should return an array of merge_requests ordered by created_at"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?sort=created_at"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
3
json_response
.
first
[
'id'
].
should
==
merge_request
.
id
json_response
.
last
[
'id'
].
should
==
merge_request_merged
.
id
end
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