2015-11-12 14:41:13 +00:00
|
|
|
module API
|
2015-11-12 15:26:39 +00:00
|
|
|
# Git Tags API
|
2015-11-12 14:41:13 +00:00
|
|
|
class Tags < Grape::API
|
|
|
|
before { authenticate! }
|
|
|
|
before { authorize! :download_code, user_project }
|
|
|
|
|
|
|
|
resource :projects do
|
|
|
|
# Get a project repository tags
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# id (required) - The ID of a project
|
|
|
|
# Example Request:
|
|
|
|
# GET /projects/:id/repository/tags
|
|
|
|
get ":id/repository/tags" do
|
|
|
|
present user_project.repo.tags.sort_by(&:name).reverse,
|
|
|
|
with: Entities::RepoTag, project: user_project
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create tag
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# id (required) - The ID of a project
|
|
|
|
# tag_name (required) - The name of the tag
|
|
|
|
# ref (required) - Create tag from commit sha or branch
|
|
|
|
# message (optional) - Specifying a message creates an annotated tag.
|
|
|
|
# Example Request:
|
|
|
|
# POST /projects/:id/repository/tags
|
|
|
|
post ':id/repository/tags' do
|
|
|
|
authorize_push_project
|
|
|
|
message = params[:message] || nil
|
|
|
|
result = CreateTagService.new(user_project, current_user).
|
2015-11-12 22:52:02 +00:00
|
|
|
execute(params[:tag_name], params[:ref], message, params[:release_description])
|
2015-11-12 14:41:13 +00:00
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
present result[:tag],
|
|
|
|
with: Entities::RepoTag,
|
|
|
|
project: user_project
|
|
|
|
else
|
|
|
|
render_api_error!(result[:message], 400)
|
|
|
|
end
|
|
|
|
end
|
2015-11-12 15:26:39 +00:00
|
|
|
|
2016-01-08 09:10:04 +00:00
|
|
|
# Delete tag
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# id (required) - The ID of a project
|
|
|
|
# tag_name (required) - The name of the tag
|
|
|
|
# Example Request:
|
|
|
|
# DELETE /projects/:id/repository/tags/:tag
|
|
|
|
delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.*/ } do
|
|
|
|
authorize_push_project
|
|
|
|
result = DeleteTagService.new(user_project, current_user).
|
|
|
|
execute(params[:tag_name])
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
{
|
|
|
|
tag_name: params[:tag_name]
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render_api_error!(result[:message], result[:return_code])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-12 15:26:39 +00:00
|
|
|
# Add release notes to tag
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# id (required) - The ID of a project
|
2015-11-21 16:29:26 +00:00
|
|
|
# tag_name (required) - The name of the tag
|
2015-11-12 15:26:39 +00:00
|
|
|
# description (required) - Release notes with markdown support
|
|
|
|
# Example Request:
|
2015-11-21 21:24:34 +00:00
|
|
|
# POST /projects/:id/repository/tags/:tag_name/release
|
2015-11-21 17:51:41 +00:00
|
|
|
post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.*/ } do
|
2015-11-12 15:26:39 +00:00
|
|
|
authorize_push_project
|
|
|
|
required_attributes! [:description]
|
2015-11-21 17:08:45 +00:00
|
|
|
result = CreateReleaseService.new(user_project, current_user).
|
|
|
|
execute(params[:tag_name], params[:description])
|
2015-11-12 15:26:39 +00:00
|
|
|
|
2015-11-21 17:08:45 +00:00
|
|
|
if result[:status] == :success
|
|
|
|
present result[:release], with: Entities::Release
|
|
|
|
else
|
2015-11-21 21:24:34 +00:00
|
|
|
render_api_error!(result[:message], result[:http_status])
|
2015-11-21 17:08:45 +00:00
|
|
|
end
|
2015-11-12 15:26:39 +00:00
|
|
|
end
|
2015-11-21 21:34:53 +00:00
|
|
|
|
|
|
|
# Updates a release notes of a tag
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# id (required) - The ID of a project
|
|
|
|
# tag_name (required) - The name of the tag
|
|
|
|
# description (required) - Release notes with markdown support
|
|
|
|
# Example Request:
|
|
|
|
# PUT /projects/:id/repository/tags/:tag_name/release
|
|
|
|
put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.*/ } do
|
|
|
|
authorize_push_project
|
|
|
|
required_attributes! [:description]
|
|
|
|
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
|
2015-11-12 14:41:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|