Commit 5ac9bdc7 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Limit to 5 the usernames/ids you can filter for approved by MRs

parent 7981eae9
...@@ -54,7 +54,7 @@ Parameters: ...@@ -54,7 +54,7 @@ Parameters:
| `author_id` | integer | no | Returns merge requests created by the given user `id`. Combine with `scope=all` or `scope=assigned_to_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`. `None` returns unassigned merge requests. `Any` returns merge requests with an assignee. | | `assignee_id` | integer | no | Returns merge requests assigned to the given user `id`. `None` returns unassigned merge requests. `Any` returns merge requests with an assignee. |
| `approver_ids` **(STARTER)** | integer array | no | Returns merge requests which have specified all the users with the given `id`s as individual approvers. `None` returns merge requests without approvers. `Any` returns merge requests with an approver. | | `approver_ids` **(STARTER)** | integer array | no | Returns merge requests which have specified all the users with the given `id`s as individual approvers. `None` returns merge requests without approvers. `Any` returns merge requests with an approver. |
| `approved_by_ids` **(STARTER)** | integer array | no | Returns merge requests which have been approved by all the users with the given `id`s. `None` returns merge requests with no approvals. `Any` returns merge requests with an approval. | | `approved_by_ids` **(STARTER)** | integer array | no | Returns merge requests which have been approved by all the users with the given `id`s (Max: 5). `None` returns merge requests with no approvals. `Any` returns merge requests with an approval. |
| `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji`. `None` returns issues not given a reaction. `Any` returns issues given at least one reaction. _([Introduced][ce-14016] in GitLab 10.0)_ | | `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji`. `None` returns issues not given a reaction. `Any` returns issues given at least one reaction. _([Introduced][ce-14016] in GitLab 10.0)_ |
| `source_branch` | string | no | Return merge requests with the given source branch | | `source_branch` | string | no | Return merge requests with the given source branch |
| `target_branch` | string | no | Return merge requests with the given target branch | | `target_branch` | string | no | Return merge requests with the given target branch |
...@@ -230,7 +230,7 @@ Parameters: ...@@ -230,7 +230,7 @@ Parameters:
| `author_id` | integer | no | Returns merge requests created by the given user `id` _([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`. `None` returns unassigned merge requests. `Any` returns merge requests with an assignee. _([Introduced][ce-13060] in GitLab 9.5)_ | | `assignee_id` | integer | no | Returns merge requests assigned to the given user `id`. `None` returns unassigned merge requests. `Any` returns merge requests with an assignee. _([Introduced][ce-13060] in GitLab 9.5)_ |
| `approver_ids` **(STARTER)** | integer array | no | Returns merge requests which have specified all the users with the given `id`s as individual approvers. `None` returns merge requests without approvers. `Any` returns merge requests with an approver. | | `approver_ids` **(STARTER)** | integer array | no | Returns merge requests which have specified all the users with the given `id`s as individual approvers. `None` returns merge requests without approvers. `Any` returns merge requests with an approver. |
| `approved_by_ids` **(STARTER)** | integer array | no | Returns merge requests which have been approved by all the users with the given `id`s. `None` returns merge requests with no approvals. `Any` returns merge requests with an approval. | | `approved_by_ids` **(STARTER)** | integer array | no | Returns merge requests which have been approved by all the users with the given `id`s (Max: 5). `None` returns merge requests with no approvals. `Any` returns merge requests with an approval. |
| `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji`. `None` returns issues not given a reaction. `Any` returns issues given at least one reaction. _([Introduced][ce-14016] in GitLab 10.0)_ | | `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji`. `None` returns issues not given a reaction. `Any` returns issues given at least one reaction. _([Introduced][ce-14016] in GitLab 10.0)_ |
| `source_branch` | string | no | Return merge requests with the given source branch | | `source_branch` | string | no | Return merge requests with the given source branch |
| `target_branch` | string | no | Return merge requests with the given target branch | | `target_branch` | string | no | Return merge requests with the given target branch |
...@@ -392,7 +392,7 @@ Parameters: ...@@ -392,7 +392,7 @@ Parameters:
| `author_id` | integer | no | Returns merge requests created by the given user `id` _([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`. `None` returns unassigned merge requests. `Any` returns merge requests with an assignee. _([Introduced][ce-13060] in GitLab 9.5)_ | | `assignee_id` | integer | no | Returns merge requests assigned to the given user `id`. `None` returns unassigned merge requests. `Any` returns merge requests with an assignee. _([Introduced][ce-13060] in GitLab 9.5)_ |
| `approver_ids` **(STARTER)** | integer array | no | Returns merge requests which have specified all the users with the given `id`s as individual approvers. `None` returns merge requests without approvers. `Any` returns merge requests with an approver. | | `approver_ids` **(STARTER)** | integer array | no | Returns merge requests which have specified all the users with the given `id`s as individual approvers. `None` returns merge requests without approvers. `Any` returns merge requests with an approver. |
| `approved_by_ids` **(STARTER)** | integer array | no | Returns merge requests which have been approved by all the users with the given `id`s. `None` returns merge requests with no approvals. `Any` returns merge requests with an approval. | | `approved_by_ids` **(STARTER)** | integer array | no | Returns merge requests which have been approved by all the users with the given `id`s (Max: 5). `None` returns merge requests with no approvals. `Any` returns merge requests with an approval. |
| `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji`. `None` returns issues not given a reaction. `Any` returns issues given at least one reaction. _([Introduced][ce-14016] in GitLab 10.0)_ | | `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji`. `None` returns issues not given a reaction. `Any` returns issues given at least one reaction. _([Introduced][ce-14016] in GitLab 10.0)_ |
| `source_branch` | string | no | Return merge requests with the given source branch | | `source_branch` | string | no | Return merge requests with the given source branch |
| `target_branch` | string | no | Return merge requests with the given target branch | | `target_branch` | string | no | Return merge requests with the given target branch |
......
...@@ -5,9 +5,12 @@ module MergeRequests ...@@ -5,9 +5,12 @@ module MergeRequests
class ByApprovalsFinder class ByApprovalsFinder
attr_reader :usernames, :ids attr_reader :usernames, :ids
# We apply a limitation to the amount of elements that can be part of the filter condition
MAX_FILTER_ELEMENTS = 5
def initialize(usernames, ids) def initialize(usernames, ids)
@usernames = Array(usernames).map(&:to_s).uniq @usernames = Array(usernames).map(&:to_s).uniq.take(MAX_FILTER_ELEMENTS)
@ids = Array(ids).uniq @ids = Array(ids).uniq.take(MAX_FILTER_ELEMENTS)
end end
def execute(items) def execute(items)
......
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
describe MergeRequests::ByApprovalsFinder do describe MergeRequests::ByApprovalsFinder do
set(:first_user) { create(:user) } set(:first_user) { create(:user) }
set(:second_user) { create(:user) } set(:second_user) { create(:user) }
let(:third_user) { create(:user) }
set(:merge_request_without_approvals) { create(:merge_request) } set(:merge_request_without_approvals) { create(:merge_request) }
set(:merge_request_with_first_user_approval) do set(:merge_request_with_first_user_approval) do
...@@ -57,6 +58,17 @@ describe MergeRequests::ByApprovalsFinder do ...@@ -57,6 +58,17 @@ describe MergeRequests::ByApprovalsFinder do
expect(merge_requests(ids: [first_user.id, second_user.id])).to match_array(expected_result) expect(merge_requests(ids: [first_user.id, second_user.id])).to match_array(expected_result)
expect(merge_requests(names: [first_user.username, second_user.username])).to match_array(expected_result) expect(merge_requests(names: [first_user.username, second_user.username])).to match_array(expected_result)
end end
context 'limiting max conditional elements' do
it 'returns merge requests approved by both users, considering limit of 2 being defined' do
stub_const('MergeRequests::ByApprovalsFinder::MAX_FILTER_ELEMENTS', 2)
expected_result = [merge_request_with_both_approvals]
expect(merge_requests(ids: [first_user.id, second_user.id, third_user.id])).to match_array(expected_result)
expect(merge_requests(names: [first_user.username, second_user.username, third_user.username])).to match_array(expected_result)
end
end
end end
context 'with empty params' do context 'with empty params' do
......
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