Commit 3c270ab3 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'grapify-tags' into 'master'

Grapify tags API

## What does this MR do?

Add the Grape-DSL to the tags API.

## Are there points in the code the reviewer needs to double check?

The delete endpoint only has a description but no success entity because we don't have one. We only return the branch name as JSON. Should I do something else?

## What are the relevant issue numbers?

Related to #22928

See merge request !6860
parents 198ae21e 9c3b24ed
...@@ -4,25 +4,24 @@ module API ...@@ -4,25 +4,24 @@ module API
before { authenticate! } before { authenticate! }
before { authorize! :download_code, user_project } before { authorize! :download_code, user_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do resource :projects do
# Get a project repository tags desc 'Get a project repository tags' do
# success Entities::RepoTag
# Parameters: end
# id (required) - The ID of a project
# Example Request:
# GET /projects/:id/repository/tags
get ":id/repository/tags" do get ":id/repository/tags" do
present user_project.repository.tags.sort_by(&:name).reverse, present user_project.repository.tags.sort_by(&:name).reverse,
with: Entities::RepoTag, project: user_project with: Entities::RepoTag, project: user_project
end end
# Get a single repository tag desc 'Get a single repository tag' do
# success Entities::RepoTag
# Parameters: end
# id (required) - The ID of a project params do
# tag_name (required) - The name of the tag requires :tag_name, type: String, desc: 'The name of the tag'
# Example Request: end
# GET /projects/:id/repository/tags/:tag_name
get ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do get ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
tag = user_project.repository.find_tag(params[:tag_name]) tag = user_project.repository.find_tag(params[:tag_name])
not_found!('Tag') unless tag not_found!('Tag') unless tag
...@@ -30,20 +29,21 @@ module API ...@@ -30,20 +29,21 @@ module API
present tag, with: Entities::RepoTag, project: user_project present tag, with: Entities::RepoTag, project: user_project
end end
# Create tag desc 'Create a new repository tag' do
# success Entities::RepoTag
# Parameters: end
# id (required) - The ID of a project params do
# tag_name (required) - The name of the tag requires :tag_name, type: String, desc: 'The name of the tag'
# ref (required) - Create tag from commit sha or branch requires :ref, type: String, desc: 'The commit sha or branch name'
# message (optional) - Specifying a message creates an annotated tag. optional :message, type: String, desc: 'Specifying a message creates an annotated tag'
# Example Request: optional :release_description, type: String, desc: 'Specifying release notes stored in the GitLab database'
# POST /projects/:id/repository/tags end
post ':id/repository/tags' do post ':id/repository/tags' do
authorize_push_project authorize_push_project
message = params[:message] || nil create_params = declared(params)
result = CreateTagService.new(user_project, current_user). result = CreateTagService.new(user_project, current_user).
execute(params[:tag_name], params[:ref], message, params[:release_description]) execute(create_params[:tag_name], create_params[:ref], create_params[:message], create_params[:release_description])
if result[:status] == :success if result[:status] == :success
present result[:tag], present result[:tag],
...@@ -54,15 +54,13 @@ module API ...@@ -54,15 +54,13 @@ module API
end end
end end
# Delete tag desc 'Delete a repository tag'
# params do
# Parameters: requires :tag_name, type: String, desc: 'The name of the tag'
# id (required) - The ID of a project end
# 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 delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
authorize_push_project authorize_push_project
result = DeleteTagService.new(user_project, current_user). result = DeleteTagService.new(user_project, current_user).
execute(params[:tag_name]) execute(params[:tag_name])
...@@ -75,17 +73,16 @@ module API ...@@ -75,17 +73,16 @@ module API
end end
end end
# Add release notes to tag desc 'Add a release note to a tag' do
# success Entities::Release
# Parameters: end
# id (required) - The ID of a project params do
# tag_name (required) - The name of the tag requires :tag_name, type: String, desc: 'The name of the tag'
# description (required) - Release notes with markdown support requires :description, type: String, desc: 'Release notes with markdown support'
# Example Request: end
# POST /projects/:id/repository/tags/:tag_name/release
post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
authorize_push_project authorize_push_project
required_attributes! [:description]
result = CreateReleaseService.new(user_project, current_user). result = CreateReleaseService.new(user_project, current_user).
execute(params[:tag_name], params[:description]) execute(params[:tag_name], params[:description])
...@@ -96,17 +93,16 @@ module API ...@@ -96,17 +93,16 @@ module API
end end
end end
# Updates a release notes of a tag desc "Update a tag's release note" do
# success Entities::Release
# Parameters: end
# id (required) - The ID of a project params do
# tag_name (required) - The name of the tag requires :tag_name, type: String, desc: 'The name of the tag'
# description (required) - Release notes with markdown support requires :description, type: String, desc: 'Release notes with markdown support'
# Example Request: end
# PUT /projects/:id/repository/tags/:tag_name/release
put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
authorize_push_project authorize_push_project
required_attributes! [:description]
result = UpdateReleaseService.new(user_project, current_user). result = UpdateReleaseService.new(user_project, current_user).
execute(params[:tag_name], params[:description]) execute(params[:tag_name], params[:description])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment