2018-09-29 22:34:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-12 14:41:13 +00:00
|
|
|
module API
|
2020-10-15 00:08:42 +00:00
|
|
|
class Tags < ::API::Base
|
2017-01-17 04:45:07 +00:00
|
|
|
include PaginationParams
|
|
|
|
|
2018-11-08 12:18:17 +00:00
|
|
|
TAG_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(tag_name: API::NO_SLASH_URL_PART_REGEX)
|
2017-07-26 13:53:07 +00:00
|
|
|
|
2022-07-05 21:08:45 +00:00
|
|
|
before do
|
|
|
|
authorize! :download_code, user_project
|
|
|
|
|
|
|
|
not_found! unless user_project.repo_exists?
|
|
|
|
end
|
2015-11-12 14:41:13 +00:00
|
|
|
|
2016-10-13 15:18:06 +00:00
|
|
|
params do
|
2022-11-03 15:11:31 +00:00
|
|
|
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
|
2016-10-13 15:18:06 +00:00
|
|
|
end
|
2018-11-08 12:18:17 +00:00
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2016-10-13 15:18:06 +00:00
|
|
|
desc 'Get a project repository tags' do
|
2022-11-01 21:09:16 +00:00
|
|
|
is_array true
|
|
|
|
success code: 200, model: Entities::Tag
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' },
|
|
|
|
{ code: 422, message: 'Unprocessable entity' },
|
|
|
|
{ code: 503, message: 'Service unavailable' }
|
|
|
|
]
|
|
|
|
tags %w[tags]
|
2016-10-13 15:18:06 +00:00
|
|
|
end
|
2017-01-17 04:45:07 +00:00
|
|
|
params do
|
2017-12-14 13:42:15 +00:00
|
|
|
optional :sort, type: String, values: %w[asc desc], default: 'desc',
|
|
|
|
desc: 'Return tags sorted in updated by `asc` or `desc` order.'
|
2022-09-13 12:12:50 +00:00
|
|
|
optional :order_by, type: String, values: %w[name updated version], default: 'updated',
|
|
|
|
desc: 'Return tags ordered by `name`, `updated`, `version` fields.'
|
2019-01-21 10:01:00 +00:00
|
|
|
optional :search, type: String, desc: 'Return list of tags matching the search criteria'
|
2021-11-17 12:11:55 +00:00
|
|
|
optional :page_token, type: String, desc: 'Name of tag to start the paginaition from'
|
2017-01-17 04:45:07 +00:00
|
|
|
use :pagination
|
|
|
|
end
|
2021-11-12 18:12:20 +00:00
|
|
|
get ':id/repository/tags', feature_category: :source_code_management, urgency: :low do
|
2021-11-17 12:11:55 +00:00
|
|
|
tags_finder = ::TagsFinder.new(user_project.repository,
|
2019-01-21 10:01:00 +00:00
|
|
|
sort: "#{params[:order_by]}_#{params[:sort]}",
|
2021-11-17 12:11:55 +00:00
|
|
|
search: params[:search],
|
|
|
|
page_token: params[:page_token],
|
|
|
|
per_page: params[:per_page])
|
2017-12-14 13:42:15 +00:00
|
|
|
|
2021-11-17 12:11:55 +00:00
|
|
|
paginated_tags = Gitlab::Pagination::GitalyKeysetPager.new(self, user_project).paginate(tags_finder)
|
2021-03-17 15:09:03 +00:00
|
|
|
|
2022-02-15 00:15:45 +00:00
|
|
|
present_cached paginated_tags, with: Entities::Tag, project: user_project, cache_context: -> (_tag) { user_project.cache_key }
|
2021-11-12 15:12:37 +00:00
|
|
|
|
2021-11-17 12:11:55 +00:00
|
|
|
rescue Gitlab::Git::InvalidPageToken => e
|
|
|
|
unprocessable_entity!(e.message)
|
2021-11-12 15:12:37 +00:00
|
|
|
rescue Gitlab::Git::CommandError
|
|
|
|
service_unavailable!
|
2015-11-12 14:41:13 +00:00
|
|
|
end
|
|
|
|
|
2016-10-13 15:18:06 +00:00
|
|
|
desc 'Get a single repository tag' do
|
2022-11-01 21:09:16 +00:00
|
|
|
success code: 200, model: Entities::Tag
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[tags]
|
2016-10-13 15:18:06 +00:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :tag_name, type: String, desc: 'The name of the tag'
|
|
|
|
end
|
2020-10-30 18:08:56 +00:00
|
|
|
get ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS, feature_category: :source_code_management do
|
2016-04-06 11:59:50 +00:00
|
|
|
tag = user_project.repository.find_tag(params[:tag_name])
|
|
|
|
not_found!('Tag') unless tag
|
|
|
|
|
2017-10-05 08:48:05 +00:00
|
|
|
present tag, with: Entities::Tag, project: user_project
|
2016-04-06 11:59:50 +00:00
|
|
|
end
|
|
|
|
|
2016-10-13 15:18:06 +00:00
|
|
|
desc 'Create a new repository tag' do
|
2022-11-01 21:09:16 +00:00
|
|
|
success code: 201, model: Entities::Tag
|
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[tags]
|
2016-10-13 15:18:06 +00:00
|
|
|
end
|
|
|
|
params do
|
2022-11-01 21:09:16 +00:00
|
|
|
requires :tag_name, type: String, desc: 'The name of the tag', documentation: { example: 'v.1.0.0' }
|
|
|
|
requires :ref, type: String, desc: 'The commit sha or branch name', documentation: { example: '2695effb5807a22ff3d138d593fd856244e155e7' }
|
|
|
|
optional :message, type: String, desc: 'Specifying a message creates an annotated tag', documentation: { example: 'Release 1.0.0' }
|
2016-10-13 15:18:06 +00:00
|
|
|
end
|
2020-10-30 18:08:56 +00:00
|
|
|
post ':id/repository/tags', :release_orchestration do
|
2019-06-19 07:08:56 +00:00
|
|
|
authorize_admin_tag
|
2016-10-13 15:18:06 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
result = ::Tags::CreateService.new(user_project, current_user)
|
2018-12-13 11:08:53 +00:00
|
|
|
.execute(params[:tag_name], params[:ref], params[:message])
|
2015-11-12 14:41:13 +00:00
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
present result[:tag],
|
2017-10-05 08:48:05 +00:00
|
|
|
with: Entities::Tag,
|
2015-11-12 14:41:13 +00:00
|
|
|
project: user_project
|
|
|
|
else
|
|
|
|
render_api_error!(result[:message], 400)
|
|
|
|
end
|
|
|
|
end
|
2015-11-12 15:26:39 +00:00
|
|
|
|
2022-11-01 21:09:16 +00:00
|
|
|
desc 'Delete a repository tag' do
|
|
|
|
success code: 204
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' },
|
|
|
|
{ code: 412, message: 'Precondition failed' }
|
|
|
|
]
|
|
|
|
tags %w[tags]
|
|
|
|
end
|
2016-10-13 15:18:06 +00:00
|
|
|
params do
|
|
|
|
requires :tag_name, type: String, desc: 'The name of the tag'
|
|
|
|
end
|
2020-10-30 18:08:56 +00:00
|
|
|
delete ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS, feature_category: :source_code_management do
|
2019-06-19 07:08:56 +00:00
|
|
|
authorize_admin_tag
|
2016-10-13 15:18:06 +00:00
|
|
|
|
2017-03-02 13:21:36 +00:00
|
|
|
tag = user_project.repository.find_tag(params[:tag_name])
|
|
|
|
not_found!('Tag') unless tag
|
|
|
|
|
|
|
|
commit = user_project.repository.commit(tag.dereferenced_target)
|
|
|
|
|
2017-08-30 12:33:39 +00:00
|
|
|
destroy_conditionally!(commit, last_updated: commit.authored_date) do
|
2017-03-02 13:21:36 +00:00
|
|
|
result = ::Tags::DestroyService.new(user_project, current_user)
|
|
|
|
.execute(params[:tag_name])
|
2016-01-08 09:10:04 +00:00
|
|
|
|
2017-03-02 13:21:36 +00:00
|
|
|
if result[:status] != :success
|
|
|
|
render_api_error!(result[:message], result[:return_code])
|
|
|
|
end
|
2016-01-08 09:10:04 +00:00
|
|
|
end
|
|
|
|
end
|
2018-12-25 09:48:26 +00:00
|
|
|
end
|
2015-11-12 14:41:13 +00:00
|
|
|
end
|
|
|
|
end
|