summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <2900-razer6@users.noreply.gitlab.com>2019-01-21 10:01:00 +0000
committerRémy Coutable <remy@rymai.me>2019-01-21 10:01:00 +0000
commit951989070048dbba127255d6e620cbd108ada9df (patch)
tree6e0c29dffebe0cd1ff6143ad6522a0154a748033
parent764f26785a0af9aaa472537e56386ffd5ce3d875 (diff)
downloadgitlab-ce-951989070048dbba127255d6e620cbd108ada9df.tar.gz
Search project tags via API
-rw-r--r--changelogs/unreleased/api-tags-search.yml5
-rw-r--r--doc/api/tags.md3
-rw-r--r--lib/api/tags.rb7
-rw-r--r--spec/requests/api/tags_spec.rb12
4 files changed, 25 insertions, 2 deletions
diff --git a/changelogs/unreleased/api-tags-search.yml b/changelogs/unreleased/api-tags-search.yml
new file mode 100644
index 00000000000..1501acd5a9e
--- /dev/null
+++ b/changelogs/unreleased/api-tags-search.yml
@@ -0,0 +1,5 @@
+---
+title: 'API: Support searching for tags'
+merge_request: 24385
+author: Robert Schilling
+type: added
diff --git a/doc/api/tags.md b/doc/api/tags.md
index fc86aaa6757..23dbf2d9ff7 100644
--- a/doc/api/tags.md
+++ b/doc/api/tags.md
@@ -17,6 +17,9 @@ Parameters:
| `id` | integer/string| yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user|
| `order_by` | string | no | Return tags ordered by `name` or `updated` fields. Default is `updated` |
| `sort` | string | no | Return tags sorted in `asc` or `desc` order. Default is `desc` |
+| `search` | string | no | Return list of tags matching the search criteria |
+
+> Support for `search` was [introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/54401) in GitLab 11.8.
```json
[
diff --git a/lib/api/tags.rb b/lib/api/tags.rb
index aacdca3871a..f5359fd316c 100644
--- a/lib/api/tags.rb
+++ b/lib/api/tags.rb
@@ -20,12 +20,15 @@ module API
desc: 'Return tags sorted in updated by `asc` or `desc` order.'
optional :order_by, type: String, values: %w[name updated], default: 'updated',
desc: 'Return tags ordered by `name` or `updated` fields.'
+ optional :search, type: String, desc: 'Return list of tags matching the search criteria'
use :pagination
end
get ':id/repository/tags' do
- tags = ::Kaminari.paginate_array(::TagsFinder.new(user_project.repository, sort: "#{params[:order_by]}_#{params[:sort]}").execute)
+ tags = ::TagsFinder.new(user_project.repository,
+ sort: "#{params[:order_by]}_#{params[:sort]}",
+ search: params[:search]).execute
- present paginate(tags), with: Entities::Tag, project: user_project
+ present paginate(::Kaminari.paginate_array(tags)), with: Entities::Tag, project: user_project
end
desc 'Get a single repository tag' do
diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb
index d09b6fe72b1..fffe878ddbd 100644
--- a/spec/requests/api/tags_spec.rb
+++ b/spec/requests/api/tags_spec.rb
@@ -54,6 +54,18 @@ describe API::Tags do
end
end
+ context 'searching' do
+ it 'only returns searched tags' do
+ get api("#{route}", user), params: { search: 'v1.1.0' }
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response.size).to eq(1)
+ expect(json_response[0]['name']).to eq('v1.1.0')
+ end
+ end
+
shared_examples_for 'repository tags' do
it 'returns the repository tags' do
get api(route, current_user)