Commit 95198907 authored by Robert Schilling's avatar Robert Schilling Committed by Rémy Coutable

Search project tags via API

parent 764f2678
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]( 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]( in GitLab 11.8.
......@@ -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
get ':id/repository/tags' do
tags = ::Kaminari.paginate_array(, sort: "#{params[:order_by]}_#{params[:sort]}").execute)
tags =,
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
desc 'Get a single repository tag' do
......@@ -54,6 +54,18 @@ describe API::Tags do
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')
shared_examples_for 'repository tags' do
it 'returns the repository tags' do
get api(route, current_user)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment