Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/merge_requests.md16
-rw-r--r--lib/api/merge_requests.rb4
-rw-r--r--spec/requests/api/merge_requests_spec.rb19
3 files changed, 31 insertions, 8 deletions
diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md
index 93b5f1c22e6..d0725b5e06e 100644
--- a/doc/api/merge_requests.md
+++ b/doc/api/merge_requests.md
@@ -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
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 3b57959162e..8810d4e441d 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -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
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 02daca0d11d..2760c4ffde2 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -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