2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
2018-11-28 19:06:02 +00:00
|
|
|
prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }
|
|
|
|
|
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
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
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)
|
2018-12-05 14:39:15 +00:00
|
|
|
@tags_pipelines = @project.ci_pipelines.latest_successful_for_refs(tag_names)
|
2017-03-13 16:00:07 +00:00
|
|
|
@releases = project.releases.where(tag: tag_names)
|
2018-09-03 10:54:06 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.atom { render layout: 'xml.atom' }
|
|
|
|
end
|
2015-11-05 12:49:34 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-11-05 12:49:34 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-11-05 12:49:34 +00:00
|
|
|
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
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2013-07-16 20:12:52 +00:00
|
|
|
|
|
|
|
def create
|
2018-12-17 09:53:17 +00:00
|
|
|
result = ::Tags::CreateService.new(@project, current_user)
|
2018-12-13 11:08:53 +00:00
|
|
|
.execute(params[:tag_name], params[:ref], params[:message])
|
2015-01-12 07:51:31 +00:00
|
|
|
|
2014-07-27 17:56:33 +00:00
|
|
|
if result[:status] == :success
|
2018-12-13 11:08:53 +00:00
|
|
|
# Release creation with Tags was deprecated in GitLab 11.7
|
|
|
|
if params[:release_description].present?
|
|
|
|
CreateReleaseService.new(@project, current_user)
|
|
|
|
.execute(params[:tag_name], params[:release_description])
|
|
|
|
end
|
|
|
|
|
2014-07-27 17:56:33 +00:00
|
|
|
@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
|
2018-12-17 09:53:17 +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
|
2018-07-02 10:43:06 +00:00
|
|
|
redirect_to project_tags_path(@project), status: :see_other
|
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
|