gitlab-org--gitlab-foss/lib/api/tags.rb

118 lines
4.1 KiB
Ruby
Raw Normal View History

module API
class Tags < Grape::API
include PaginationParams
TAG_ENDPOINT_REQUIREMENTS = API::PROJECT_ENDPOINT_REQUIREMENTS.merge(tag_name: API::NO_SLASH_URL_PART_REGEX)
before { authorize! :download_code, user_project }
2016-10-13 15:18:06 +00:00
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
2016-10-13 15:18:06 +00:00
desc 'Get a project repository tags' do
success Entities::RepoTag
end
params do
use :pagination
end
get ':id/repository/tags' do
tags = ::Kaminari.paginate_array(user_project.repository.tags.sort_by(&:name).reverse)
present paginate(tags), with: Entities::RepoTag, project: user_project
end
2016-10-13 15:18:06 +00:00
desc 'Get a single repository tag' do
success Entities::RepoTag
end
params do
requires :tag_name, type: String, desc: 'The name of the tag'
end
get ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS do
2016-04-06 11:59:50 +00:00
tag = user_project.repository.find_tag(params[:tag_name])
not_found!('Tag') unless tag
present tag, with: Entities::RepoTag, 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
success Entities::RepoTag
end
params do
requires :tag_name, type: String, desc: 'The name of the tag'
requires :ref, type: String, desc: 'The commit sha or branch name'
optional :message, type: String, desc: 'Specifying a message creates an annotated tag'
optional :release_description, type: String, desc: 'Specifying release notes stored in the GitLab database'
end
post ':id/repository/tags' do
authorize_push_project
2016-10-13 15:18:06 +00:00
2017-06-21 13:48:12 +00:00
result = ::Tags::CreateService.new(user_project, current_user)
.execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
if result[:status] == :success
present result[:tag],
with: Entities::RepoTag,
project: user_project
else
render_api_error!(result[:message], 400)
end
end
2016-10-13 15:18:06 +00:00
desc 'Delete a repository tag'
params do
requires :tag_name, type: String, desc: 'The name of the tag'
end
delete ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS do
2016-01-08 09:10:04 +00:00
authorize_push_project
2016-10-13 15:18:06 +00:00
2017-06-21 13:48:12 +00:00
result = ::Tags::DestroyService.new(user_project, current_user)
.execute(params[:tag_name])
2016-01-08 09:10:04 +00:00
2017-02-20 18:18:12 +00:00
if result[:status] != :success
2016-01-08 09:10:04 +00:00
render_api_error!(result[:message], result[:return_code])
end
end
2016-10-13 15:18:06 +00:00
desc 'Add a release note to a tag' do
success Entities::Release
end
params do
requires :tag_name, type: String, desc: 'The name of the tag'
requires :description, type: String, desc: 'Release notes with markdown support'
end
post ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS do
authorize_push_project
2016-10-13 15:18:06 +00:00
2017-06-21 13:48:12 +00:00
result = CreateReleaseService.new(user_project, current_user)
.execute(params[:tag_name], params[:description])
if result[:status] == :success
present result[:release], with: Entities::Release
else
render_api_error!(result[:message], result[:http_status])
end
end
2016-10-13 15:18:06 +00:00
desc "Update a tag's release note" do
success Entities::Release
end
params do
requires :tag_name, type: String, desc: 'The name of the tag'
requires :description, type: String, desc: 'Release notes with markdown support'
end
put ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS do
authorize_push_project
2016-10-13 15:18:06 +00:00
2017-06-21 13:48:12 +00:00
result = UpdateReleaseService.new(user_project, current_user)
.execute(params[:tag_name], params[:description])
if result[:status] == :success
present result[:release], with: Entities::Release
else
render_api_error!(result[:message], result[:http_status])
end
end
end
end
end