Commit 7429a1f1 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '38318-search-merge-requests-with-api' into 'master'

Resolve "Search merge-requests with API"

Closes #38318

See merge request gitlab-org/gitlab-ce!16029
parents cc8ff768 055543b9
---
title: Add optional search param for Merge Requests API
merge_request:
author:
type: fixed
...@@ -47,6 +47,7 @@ Parameters: ...@@ -47,6 +47,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` | | `assignee_id` | integer | no | Returns merge requests assigned to the given user `id` |
| `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ | | `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `search` | string | no | Search merge requests against their `title` and `description` |
```json ```json
[ [
...@@ -161,6 +162,7 @@ Parameters: ...@@ -161,6 +162,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` _([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)_ |
| `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ | | `my_reaction_emoji` | string | no | Return merge requests reacted by the authenticated user by the given `emoji` _([Introduced][ce-14016] in GitLab 10.0)_ |
| `search` | string | no | Search merge requests against their `title` and `description` |
```json ```json
[ [
......
...@@ -8,7 +8,7 @@ module API ...@@ -8,7 +8,7 @@ module API
helpers do helpers do
def find_issues(args = {}) def find_issues(args = {})
args = params.merge(args) args = declared_params.merge(args)
args.delete(:id) args.delete(:id)
args[:milestone_title] = args.delete(:milestone) args[:milestone_title] = args.delete(:milestone)
......
...@@ -8,7 +8,7 @@ module API ...@@ -8,7 +8,7 @@ module API
helpers do helpers do
def find_merge_requests(args = {}) def find_merge_requests(args = {})
args = params.merge(args) args = declared_params.merge(args)
args[:milestone_title] = args.delete(:milestone) args[:milestone_title] = args.delete(:milestone)
args[:label_name] = args.delete(:labels) args[:label_name] = args.delete(:labels)
...@@ -41,6 +41,7 @@ module API ...@@ -41,6 +41,7 @@ module API
optional :scope, type: String, values: %w[created-by-me assigned-to-me 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`' desc: 'Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`'
optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji' optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji'
optional :search, type: String, desc: 'Search merge requests for text present in the title or description'
use :pagination use :pagination
end end
end end
......
...@@ -150,6 +150,26 @@ describe API::MergeRequests do ...@@ -150,6 +150,26 @@ describe API::MergeRequests do
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request3.id) expect(json_response.first['id']).to eq(merge_request3.id)
end end
context 'search params' do
before do
merge_request.update(title: 'Search title', description: 'Search description')
end
it 'returns merge requests matching given search string for title' do
get api("/merge_requests", user), search: merge_request.title
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request.id)
end
it 'returns merge requests for project matching given search string for description' do
get api("/merge_requests", user), project_id: project.id, search: merge_request.description
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request.id)
end
end
end end
end end
......
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