debian-mirror-gitlab/app/controllers/projects/tags_controller.rb

77 lines
2 KiB
Ruby
Raw Normal View History

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