Commit ac5cfc3a authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '54401-search-project-tags-via-api' into 'master'

Search project tags via API

Closes #54401

See merge request gitlab-org/gitlab-ce!24385
parents 764f2678 95198907
---
title: 'API: Support searching for tags'
merge_request: 24385
author: Robert Schilling
type: added
......@@ -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
[
......
......@@ -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
......
......@@ -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)
......
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