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
a801e16d
Commit
a801e16d
authored
Jul 11, 2017
by
Sean McGivern
Committed by
Stan Hu
Jul 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'sh-add-mr-simple-mode' into 'master'
Add a simple mode to merge request API Closes #34920 See merge request !12766
parent
ebcc5989
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
5 deletions
+48
-5
sh-add-mr-simple-mode.yml
changelogs/unreleased/sh-add-mr-simple-mode.yml
+4
-0
merge_requests.md
doc/api/merge_requests.md
+1
-0
entities.rb
lib/api/entities.rb
+7
-0
merge_requests.rb
lib/api/merge_requests.rb
+20
-5
merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+16
-0
No files found.
changelogs/unreleased/sh-add-mr-simple-mode.yml
0 → 100644
View file @
a801e16d
---
title
:
Add a simple mode to merge request API
merge_request
:
author
:
doc/api/merge_requests.md
View file @
a801e16d
...
...
@@ -25,6 +25,7 @@ Parameters:
|
`order_by`
| string | no | Return requests ordered by
`created_at`
or
`updated_at`
fields. Default is
`created_at`
|
|
`sort`
| string | no | Return requests sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
|
`milestone`
| string | no | Return merge requests for a specific milestone |
|
`view`
| string | no | If
`simple`
, returns the
`iid`
, URL, title, description, and basic state of merge request |
|
`labels`
| string | no | Return merge requests matching a comma separated list of labels |
|
`created_after`
| datetime | no | Return merge requests created after the given time (inclusive) |
|
`created_before`
| datetime | no | Return merge requests created before the given time (inclusive) |
...
...
lib/api/entities.rb
View file @
a801e16d
...
...
@@ -314,6 +314,13 @@ module API
expose
:id
end
class
MergeRequestSimple
<
ProjectEntity
expose
:title
expose
:web_url
do
|
merge_request
,
options
|
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
end
end
class
MergeRequestBasic
<
ProjectEntity
expose
:target_branch
,
:source_branch
expose
:upvotes
do
|
merge_request
,
options
|
...
...
lib/api/merge_requests.rb
View file @
a801e16d
...
...
@@ -44,9 +44,14 @@ module API
args
[
:label_name
]
=
args
.
delete
(
:labels
)
merge_requests
=
MergeRequestsFinder
.
new
(
current_user
,
args
).
execute
merge_requests
=
merge_requests
.
reorder
(
args
[
:order_by
]
=>
args
[
:sort
])
paginate
(
merge_requests
)
.
preload
(
:notes
,
:target_project
,
:author
,
:assignee
,
:milestone
,
:merge_request_diff
,
:labels
)
.
reorder
(
args
[
:order_by
]
=>
args
[
:sort
])
merge_requests
=
paginate
(
merge_requests
)
.
preload
(
:target_project
)
return
merge_requests
if
args
[
:view
]
==
'simple'
merge_requests
.
preload
(
:notes
,
:author
,
:assignee
,
:milestone
,
:merge_request_diff
,
:labels
)
end
params
:optional_params_ce
do
...
...
@@ -77,15 +82,25 @@ module API
optional
:labels
,
type:
String
,
desc:
'Comma-separated list of label names'
optional
:created_after
,
type:
DateTime
,
desc:
'Return merge requests created after the specified time'
optional
:created_before
,
type:
DateTime
,
desc:
'Return merge requests created before the specified time'
optional
:view
,
type:
String
,
values:
%w[simple]
,
desc:
'If simple, returns the `iid`, URL, title, description, and basic state of merge request'
use
:pagination
end
get
":id/merge_requests"
do
authorize!
:read_merge_request
,
user_project
merge_requests
=
find_merge_requests
(
project_id:
user_project
.
id
)
issuable_metadata
=
issuable_meta_data
(
merge_requests
,
'MergeRequest'
)
present
merge_requests
,
with:
Entities
::
MergeRequestBasic
,
current_user:
current_user
,
project:
user_project
,
issuable_metadata:
issuable_metadata
options
=
{
with:
Entities
::
MergeRequestBasic
,
current_user:
current_user
,
project:
user_project
}
if
params
[
:view
]
==
'simple'
options
[
:with
]
=
Entities
::
MergeRequestSimple
else
options
[
:issuable_metadata
]
=
issuable_meta_data
(
merge_requests
,
'MergeRequest'
)
end
present
merge_requests
,
options
end
desc
'Create a merge request'
do
...
...
spec/requests/api/merge_requests_spec.rb
View file @
a801e16d
...
...
@@ -69,6 +69,22 @@ describe API::MergeRequests do
expect
(
json_response
.
first
[
'merge_commit_sha'
]).
to
eq
(
merge_request_merged
.
merge_commit_sha
)
end
it
"returns an array of all merge_requests using simple mode"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?view=simple"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
last
.
keys
).
to
match_array
(
%w(id iid title web_url created_at description project_id state updated_at)
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
last
[
'iid'
]).
to
eq
(
merge_request
.
iid
)
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
expect
(
json_response
.
last
).
to
have_key
(
'web_url'
)
expect
(
json_response
.
first
[
'iid'
]).
to
eq
(
merge_request_merged
.
iid
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
merge_request_merged
.
title
)
expect
(
json_response
.
first
).
to
have_key
(
'web_url'
)
end
it
"returns an array of all merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state"
,
user
)
...
...
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