Commit d77088bb authored by Toon Claes's avatar Toon Claes

Default /merge_request API endpoint to `scope=created-by-me`

This matches the behavior of the /issues endpoint.
parent d7505de8
......@@ -4,7 +4,12 @@ Every API call to merge requests must be authenticated.
## List merge requests
Get all merge requests the authenticated user has access to.
> [Introduced][ce-13060] in GitLab 9.5.
Get all merge requests the authenticated user has access to. By
default it returns only merge requests created by the current user. To
get all merge requests, use parameter `scope=all`.
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
......@@ -32,9 +37,9 @@ Parameters:
| `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) |
| `author_id` | integer | no | Returns merge requests created by the given user `id` |
| `scope` | string | no | Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`. Defaults to `created-by-me` |
| `author_id` | integer | no | Returns merge requests created by the given user `id`. Combine with `scope=all` or `scope=assigned-to-me` |
| `assignee_id` | integer | no | Returns merge requests assigned to the given user `id` |
| `scope` | string | no | Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all` |
```json
[
......@@ -121,6 +126,9 @@ Parameters:
| `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) |
| `scope` | string | no | Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all` _([Introduced][ce-13060] in GitLab 9.5)_ |
| `author_id` | integer | no | Returns merge requests created by the given user `id` _([Introduced][ce-13060] in GitLab 9.5)_ |
| `assignee_id` | integer | no | Returns merge requests assigned to the given user `id` _([Introduced][ce-13060] in GitLab 9.5)_ |
```json
[
......@@ -1257,3 +1265,5 @@ Example response:
"total_time_spent": 3600
}
```
[ce-13060]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13060
......@@ -38,7 +38,7 @@ module API
optional :view, type: String, values: %w[simple], desc: 'If simple, returns the `iid`, URL, title, description, and basic state of merge request'
optional :author_id, type: Integer, desc: 'Return merge requests which are authored by the user with the given ID'
optional :assignee_id, type: Integer, desc: 'Return merge requests which are assigned to the user with the given ID'
optional :scope, type: String, values: %w[created-by-me assigned-to-me all], default: 'all',
optional :scope, type: String, values: %w[created-by-me assigned-to-me all],
desc: 'Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`'
use :pagination
end
......@@ -50,6 +50,8 @@ module API
end
params do
use :merge_requests_params
optional :scope, type: String, values: %w[created-by-me assigned-to-me all], default: 'created-by-me',
desc: 'Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`'
end
get do
merge_requests = find_merge_requests
......
......@@ -41,7 +41,7 @@ describe API::MergeRequests do
let(:user2) { create(:user) }
it 'returns an array of all merge requests' do
get api('/merge_requests', user)
get api('/merge_requests', user), scope: :all
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
......@@ -54,7 +54,7 @@ describe API::MergeRequests do
private_project = create(:empty_project, :private)
merge_request3 = create(:merge_request, :simple, source_project: private_project, target_project: private_project, source_branch: 'other-branch')
get api('/merge_requests', user)
get api('/merge_requests', user), scope: :all
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
......@@ -63,10 +63,21 @@ describe API::MergeRequests do
.not_to include(merge_request3.id)
end
it 'returns an array of merge requests created by current user if no scope is given' do
merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: 'other-branch')
get api('/merge_requests', user2)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request3.id)
end
it 'returns an array of merge requests authored by the given user' do
merge_request3 = create(:merge_request, :simple, author: user2, assignee: user, source_project: project2, target_project: project2, source_branch: 'other-branch')
get api('/merge_requests', user), author_id: user2.id
get api('/merge_requests', user), author_id: user2.id, scope: :all
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
......@@ -77,7 +88,7 @@ describe API::MergeRequests do
it 'returns an array of merge requests assigned to the given user' do
merge_request3 = create(:merge_request, :simple, author: user, assignee: user2, source_project: project2, target_project: project2, source_branch: 'other-branch')
get api('/merge_requests', user), assignee_id: user2.id
get api('/merge_requests', user), assignee_id: user2.id, scope: :all
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment