debian-mirror-gitlab/lib/api/tags.rb

116 lines
3.9 KiB
Ruby
Raw Normal View History

2015-11-26 14:37:03 +05:30
module API
class Tags < Grape::API
2017-08-17 22:00:37 +05:30
include PaginationParams
2015-11-26 14:37:03 +05:30
before { authorize! :download_code, user_project }
2017-08-17 22:00:37 +05:30
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
desc 'Get a project repository tags' do
success Entities::RepoTag
end
params do
use :pagination
end
2015-11-26 14:37:03 +05:30
get ":id/repository/tags" do
2017-08-17 22:00:37 +05:30
tags = ::Kaminari.paginate_array(user_project.repository.tags.sort_by(&:name).reverse)
present paginate(tags), with: Entities::RepoTag, project: user_project
2015-11-26 14:37:03 +05:30
end
2017-08-17 22:00:37 +05:30
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
2016-06-02 11:05:42 +05:30
get ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
tag = user_project.repository.find_tag(params[:tag_name])
not_found!('Tag') unless tag
present tag, with: Entities::RepoTag, project: user_project
end
2017-08-17 22:00:37 +05:30
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
2015-11-26 14:37:03 +05:30
post ':id/repository/tags' do
authorize_push_project
2017-08-17 22:00:37 +05:30
result = ::Tags::CreateService.new(user_project, current_user).
execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
2015-11-26 14:37:03 +05:30
if result[:status] == :success
present result[:tag],
with: Entities::RepoTag,
project: user_project
else
render_api_error!(result[:message], 400)
end
end
2017-08-17 22:00:37 +05:30
desc 'Delete a repository tag'
params do
requires :tag_name, type: String, desc: 'The name of the tag'
end
2016-08-24 12:49:21 +05:30
delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
authorize_push_project
2017-08-17 22:00:37 +05:30
result = ::Tags::DestroyService.new(user_project, current_user).
execute(params[:tag_name])
2017-08-17 22:00:37 +05:30
if result[:status] != :success
render_api_error!(result[:message], result[:return_code])
end
end
2017-08-17 22:00:37 +05:30
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
2016-08-24 12:49:21 +05:30
post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
2015-11-26 14:37:03 +05:30
authorize_push_project
2017-08-17 22:00:37 +05:30
2015-11-26 14:37:03 +05:30
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
2017-08-17 22:00:37 +05:30
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
2016-08-24 12:49:21 +05:30
put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
2015-11-26 14:37:03 +05:30
authorize_push_project
2017-08-17 22:00:37 +05:30
2015-11-26 14:37:03 +05:30
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