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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
53b52b11
Commit
53b52b11
authored
Apr 13, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6699 from criteo/api_get_open_merge_requests
Add optional parameter to list merge requests
parents
481bbd75
66209fbc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
4 deletions
+52
-4
doc/api/merge_requests.md
doc/api/merge_requests.md
+8
-2
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+11
-1
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+33
-1
No files found.
doc/api/merge_requests.md
View file @
53b52b11
## List merge requests
Get all merge requests for this project. This function takes pagination parameters
`page`
and
`per_page`
to restrict the list of merge requests.
Get all merge requests for this project.
The
`state`
parameter can be used to get only merge requests with a
given state (
`opened`
,
`closed`
, or
`merged`
) or all of them (
`all`
).
The pagination parameters
`page`
and
`per_page`
can be used to restrict the
list of merge requests.
```
GET /projects/:id/merge_requests
GET /projects/:id/merge_requests?state=opened
GET /projects/:id/merge_requests?state=all
```
Parameters:
+
`id`
(required) - The ID of a project
+
`state`
(optional) - Return
`all`
requests or just those that are
`merged`
,
`opened`
or
`closed`
```
json
[
...
...
lib/api/merge_requests.rb
View file @
53b52b11
...
...
@@ -19,14 +19,24 @@ module API
#
# Parameters:
# id (required) - The ID of a project
# state (optional) - Return requests "merged", "opened" or "closed"
#
# Example:
# GET /projects/:id/merge_requests
# GET /projects/:id/merge_requests?state=opened
# GET /projects/:id/merge_requests?state=closed
#
get
":id/merge_requests"
do
authorize!
:read_merge_request
,
user_project
present
paginate
(
user_project
.
merge_requests
),
with:
Entities
::
MergeRequest
mrs
=
case
params
[
"state"
]
when
"opened"
then
user_project
.
merge_requests
.
opened
when
"closed"
then
user_project
.
merge_requests
.
closed
when
"merged"
then
user_project
.
merge_requests
.
merged
else
user_project
.
merge_requests
end
present
paginate
(
mrs
),
with:
Entities
::
MergeRequest
end
# Show MR
...
...
spec/requests/api/merge_requests_spec.rb
View file @
53b52b11
...
...
@@ -7,6 +7,8 @@ describe API::API, api: true do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
assignee:
user
,
source_project:
project
,
target_project:
project
,
title:
"Test"
)
}
let!
(
:merge_request_closed
)
{
create
(
:merge_request
,
state:
"closed"
,
author:
user
,
assignee:
user
,
source_project:
project
,
target_project:
project
,
title:
"Closed test"
)
}
let!
(
:merge_request_merged
)
{
create
(
:merge_request
,
state:
"merged"
,
author:
user
,
assignee:
user
,
source_project:
project
,
target_project:
project
,
title:
"Merged test"
)
}
let!
(
:note
)
{
create
(
:note_on_merge_request
,
author:
user
,
project:
project
,
noteable:
merge_request
,
note:
"a comment on a MR"
)
}
before
{
project
.
team
<<
[
user
,
:reporters
]
...
...
@@ -21,12 +23,42 @@ describe API::API, api: true do
end
context
"when authenticated"
do
it
"should return an array of merge_requests"
do
it
"should return an array of
all
merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
3
json_response
.
first
[
'title'
].
should
==
merge_request
.
title
end
it
"should return an array of all merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
3
json_response
.
first
[
'title'
].
should
==
merge_request
.
title
end
it
"should return an array of open merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state=opened"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
1
json_response
.
first
[
'title'
].
should
==
merge_request
.
title
end
it
"should return an array of closed merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state=closed"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
2
json_response
.
first
[
'title'
].
should
==
merge_request_closed
.
title
json_response
.
second
[
'title'
].
should
==
merge_request_merged
.
title
end
it
"should return an array of merged merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state=merged"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
1
json_response
.
first
[
'title'
].
should
==
merge_request_merged
.
title
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