tags.rb 1.17 KB
Newer Older
Robert Schilling's avatar
Robert Schilling committed
1 2 3 4 5 6 7 8
module API
  module V3
    class Tags < Grape::API
      before { authorize! :download_code, user_project }

      params do
        requires :id, type: String, desc: 'The ID of a project'
      end
9
      resource :projects, requirements: { id: %r{[^/]+} } do
Robert Schilling's avatar
Robert Schilling committed
10
        desc 'Get a project repository tags' do
11
          success ::API::Entities::Tag
Robert Schilling's avatar
Robert Schilling committed
12 13 14
        end
        get ":id/repository/tags" do
          tags = user_project.repository.tags.sort_by(&:name).reverse
15
          present tags, with: ::API::Entities::Tag, project: user_project
Robert Schilling's avatar
Robert Schilling committed
16
        end
Robert Schilling's avatar
Robert Schilling committed
17 18 19 20 21 22 23 24

        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_name: /.+/ } do
          authorize_push_project

25 26
          result = ::Tags::DestroyService.new(user_project, current_user)
            .execute(params[:tag_name])
Robert Schilling's avatar
Robert Schilling committed
27 28 29 30 31 32 33 34 35 36

          if result[:status] == :success
            status(200)
            {
              tag_name: params[:tag_name]
            }
          else
            render_api_error!(result[:message], result[:return_code])
          end
        end
Robert Schilling's avatar
Robert Schilling committed
37 38 39 40
      end
    end
  end
end