Skip to content

Commit 055543b

Browse files
author
Mark Fletcher
committed
Add optional search param for Merge Requests API
1 parent c9732b3 commit 055543b

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Add optional search param for Merge Requests API
3+
merge_request:
4+
author:
5+
type: fixed

doc/api/merge_requests.md

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Parameters:
4747
| `author_id` | integer | no | Returns merge requests created by the given user `id`. Combine with `scope=all` or `scope=assigned-to-me` |
4848
| `assignee_id` | integer | no | Returns merge requests assigned to the given user `id` |
4949
| `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
50+
| `search` | string | no | Search merge requests against their `title` and `description` |
5051

5152
```json
5253
[
@@ -161,6 +162,7 @@ Parameters:
161162
| `author_id` | integer | no | Returns merge requests created by the given user `id` _([Introduced][ce-13060] in GitLab 9.5)_ |
162163
| `assignee_id` | integer | no | Returns merge requests assigned to the given user `id` _([Introduced][ce-13060] in GitLab 9.5)_ |
163164
| `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
165+
| `search` | string | no | Search merge requests against their `title` and `description` |
164166

165167
```json
166168
[

lib/api/merge_requests.rb

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def find_merge_requests(args = {})
4141
optional :scope, type: String, values: %w[created-by-me assigned-to-me all],
4242
desc: 'Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`'
4343
optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji'
44+
optional :search, type: String, desc: 'Search merge requests for text present in the title or description'
4445
use :pagination
4546
end
4647
end

spec/requests/api/merge_requests_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,26 @@
150150
expect(json_response.length).to eq(1)
151151
expect(json_response.first['id']).to eq(merge_request3.id)
152152
end
153+
154+
context 'search params' do
155+
before do
156+
merge_request.update(title: 'Search title', description: 'Search description')
157+
end
158+
159+
it 'returns merge requests matching given search string for title' do
160+
get api("/merge_requests", user), search: merge_request.title
161+
162+
expect(json_response.length).to eq(1)
163+
expect(json_response.first['id']).to eq(merge_request.id)
164+
end
165+
166+
it 'returns merge requests for project matching given search string for description' do
167+
get api("/merge_requests", user), project_id: project.id, search: merge_request.description
168+
169+
expect(json_response.length).to eq(1)
170+
expect(json_response.first['id']).to eq(merge_request.id)
171+
end
172+
end
153173
end
154174
end
155175

0 commit comments

Comments
 (0)