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!
|
2019-06-19 07:08:56 +00:00
|
|
|
before_action :authorize_admin_tag!, only: [:new, :create, :destroy]
|
2013-07-16 20:12:52 +00:00
|
|
|
|
2020-10-08 18:08:32 +00:00
|
|
|
feature_category :source_code_management, [:index, :show, :new, :destroy]
|
|
|
|
feature_category :release_evidence, [:create]
|
|
|
|
|
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)
|
2020-10-30 03:08:51 +00:00
|
|
|
@tag_pipeline_statuses = Ci::CommitStatusesFinder.new(@project, @repository, current_user, @tags).execute
|
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
|
2020-06-16 15:08:32 +00:00
|
|
|
# TODO: remove this with the release creation moved to it's own form https://gitlab.com/gitlab-org/gitlab/-/issues/214245
|
|
|
|
evidence_pipeline = find_evidence_pipeline
|
|
|
|
|
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
|
2020-06-16 15:08:32 +00:00
|
|
|
# TODO: remove this with the release creation moved to it's own form https://gitlab.com/gitlab-org/gitlab/-/issues/214245
|
2018-12-13 11:08:53 +00:00
|
|
|
if params[:release_description].present?
|
2018-12-25 09:48:26 +00:00
|
|
|
release_params = {
|
|
|
|
tag: params[:tag_name],
|
|
|
|
name: params[:tag_name],
|
2020-06-16 15:08:32 +00:00
|
|
|
description: params[:release_description],
|
|
|
|
evidence_pipeline: evidence_pipeline
|
2018-12-25 09:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Releases::CreateService
|
|
|
|
.new(@project, current_user, release_params)
|
|
|
|
.execute
|
2018-12-13 11:08:53 +00:00
|
|
|
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
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
if result[:status] == :success
|
|
|
|
render json: result
|
|
|
|
else
|
|
|
|
render json: { message: result[:message] }, status: result[:return_code]
|
2016-03-01 17:42:56 +00:00
|
|
|
end
|
2013-07-16 20:12:52 +00:00
|
|
|
end
|
2020-06-16 15:08:32 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# TODO: remove this with the release creation moved to it's own form https://gitlab.com/gitlab-org/gitlab/-/issues/214245
|
|
|
|
def find_evidence_pipeline
|
|
|
|
evidence_pipeline_sha = @project.repository.commit(params[:ref])&.sha
|
|
|
|
return unless evidence_pipeline_sha
|
|
|
|
|
|
|
|
@project.ci_pipelines.for_sha(evidence_pipeline_sha).last
|
|
|
|
end
|
2013-07-16 20:12:52 +00:00
|
|
|
end
|