Commit 4a57a0d5 authored by James Fargher's avatar James Fargher

Merge branch '347525-epics-api-does-not-support-not-filter' into 'master'

feat: Add support for `not` filter to Epics API

See merge request gitlab-org/gitlab!76441
parents aea78559 dff47098
......@@ -77,6 +77,7 @@ GET /groups/:id/epics?state=opened
| `include_ancestor_groups` | boolean | no | Include epics from the requested group's ancestors. Default is `false` |
| `include_descendant_groups` | boolean | no | Include epics from the requested group's descendants. Default is `true` |
| `my_reaction_emoji` | string | no | Return epics reacted by the authenticated user by the given emoji. `None` returns epics not given a reaction. `Any` returns epics given at least one reaction. Available in [GitLab 13.0](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31479) and later |
| `not` | Hash | no | Return epics that do not match the parameters supplied. Accepts: `author_id` and `labels`. Available in [GitLab 14.6](https://gitlab.com/gitlab-org/gitlab/-/issues/347525) and later |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/epics"
......
......@@ -13,6 +13,13 @@ module API
helpers ::API::Helpers::EpicsHelpers
helpers do
params :negatable_epic_filter_params do
optional :labels, type: Array[String], coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce, desc: 'Comma-separated list of label names'
optional :author_id, type: Integer, desc: 'Return epics which are not authored by the user with the given ID'
end
end
params do
requires :id, type: String, desc: 'The ID of a group'
end
......@@ -41,6 +48,10 @@ module API
optional :my_reaction_emoji, type: String, desc: 'Return epics reacted by the authenticated user by the given emoji'
optional :confidential, type: Boolean, desc: 'Return epics with given confidentiality'
use :pagination
optional :not, type: Hash do
use :negatable_epic_filter_params
end
end
[':id/epics', ':id/-/epics'].each do |path|
get path do
......
......@@ -43,6 +43,8 @@ module API
def find_epics(finder_params: {}, preload: nil)
args = declared_params.merge(finder_params)
args[:label_name] = args.delete(:labels)
args[:not] ||= {}
args[:not][:label_name] ||= args[:not].delete(:labels)
epics = EpicsFinder.new(current_user, args).execute.preload(preload)
......
......@@ -204,6 +204,18 @@ RSpec.describe API::Epics do
stub_licensed_features(epics: true)
end
it 'returns epics not authored by the given author id' do
get api(url), params: { not: { author_id: user2.id } }
expect_paginated_array_response([epic.id])
end
it 'returns epics without the given label' do
get api(url), params: { not: { labels: label.title } }
expect_paginated_array_response([epic.id])
end
it 'returns epics authored by the given author id' do
get api(url), params: { author_id: user2.id }
......
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