2013-07-16 20:12:52 +00:00
|
|
|
class Projects::TagsController < Projects::ApplicationController
|
2016-08-31 10:39:35 +00:00
|
|
|
include SortingHelper
|
2016-08-31 11:35:23 +00:00
|
|
|
|
2013-07-16 20:12:52 +00:00
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
2015-12-03 17:53:17 +00:00
|
|
|
before_action :authorize_push_code!, only: [:new, :create]
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :authorize_admin_project!, only: [:destroy]
|
2013-07-16 20:12:52 +00:00
|
|
|
|
|
|
|
def index
|
2016-12-21 23:18:47 +00:00
|
|
|
params[:sort] = params[:sort].presence || sort_value_recently_updated
|
2016-08-31 11:35:23 +00:00
|
|
|
|
|
|
|
@sort = params[:sort]
|
2016-08-31 10:39:35 +00:00
|
|
|
@tags = TagsFinder.new(@repository, params).execute
|
2016-06-16 17:33:29 +00:00
|
|
|
@tags = Kaminari.paginate_array(@tags).page(params[:page])
|
|
|
|
|
2017-03-13 16:00:07 +00:00
|
|
|
tag_names = @tags.map(&:name)
|
|
|
|
@tags_pipelines = @project.pipelines.latest_successful_for_refs(tag_names)
|
|
|
|
@releases = project.releases.where(tag: tag_names)
|
2015-11-05 12:49:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@tag = @repository.find_tag(params[:id])
|
2016-07-26 15:31:25 +00:00
|
|
|
|
2016-10-05 17:31:33 +00:00
|
|
|
return render_404 unless @tag
|
2016-10-05 16:13:49 +00:00
|
|
|
|
2015-11-05 12:49:34 +00:00
|
|
|
@release = @project.releases.find_or_initialize_by(tag: @tag.name)
|
2016-09-27 03:07:31 +00:00
|
|
|
@commit = @repository.commit(@tag.dereferenced_target)
|
2013-07-16 20:12:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-06-21 13:48:12 +00:00
|
|
|
result = Tags::CreateService.new(@project, current_user)
|
|
|
|
.execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
|
2015-01-12 07:51:31 +00:00
|
|
|
|
2014-07-27 17:56:33 +00:00
|
|
|
if result[:status] == :success
|
|
|
|
@tag = result[:tag]
|
2015-11-05 13:03:48 +00:00
|
|
|
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_tag_path(@project, @tag.name)
|
2014-07-27 17:56:33 +00:00
|
|
|
else
|
|
|
|
@error = result[:message]
|
2017-05-08 02:20:37 +00:00
|
|
|
@message = params[:message]
|
|
|
|
@release_description = params[:release_description]
|
2014-07-27 17:56:33 +00:00
|
|
|
render action: 'new'
|
|
|
|
end
|
2013-07-16 20:12:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2017-03-13 17:12:32 +00:00
|
|
|
result = Tags::DestroyService.new(project, current_user).execute(params[:id])
|
2013-07-16 20:12:52 +00:00
|
|
|
|
2016-03-01 17:42:56 +00:00
|
|
|
respond_to do |format|
|
2017-03-13 17:12:32 +00:00
|
|
|
if result[:status] == :success
|
|
|
|
format.html do
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_tags_path(@project), status: 303
|
2017-03-13 17:12:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
format.js
|
|
|
|
else
|
|
|
|
@error = result[:message]
|
|
|
|
|
|
|
|
format.html do
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_tags_path(@project),
|
2017-05-08 07:41:58 +00:00
|
|
|
alert: @error, status: 303
|
2017-03-13 17:12:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
format.js do
|
|
|
|
render status: :unprocessable_entity
|
|
|
|
end
|
2016-03-01 17:42:56 +00:00
|
|
|
end
|
|
|
|
end
|
2013-07-16 20:12:52 +00:00
|
|
|
end
|
|
|
|
end
|