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

48 lines
1.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::BranchesController < Projects::ApplicationController
2015-04-26 12:48:37 +05:30
include ActionView::Helpers::SanitizeHelper
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, :destroy]
2014-09-02 18:07:02 +05:30
def index
@sort = params[:sort] || 'name'
@branches = @repository.branches_sorted_by(@sort)
2015-04-26 12:48:37 +05:30
@branches = Kaminari.paginate_array(@branches).page(params[:page]).per(PER_PAGE)
2014-09-02 18:07:02 +05:30
end
def recent
@branches = @repository.recent_branches
end
def create
2015-04-26 12:48:37 +05:30
branch_name = sanitize(strip_tags(params[:branch_name]))
2015-09-11 14:41:01 +05:30
branch_name = Addressable::URI.unescape(branch_name)
2015-04-26 12:48:37 +05:30
ref = sanitize(strip_tags(params[:ref]))
2015-09-11 14:41:01 +05:30
ref = Addressable::URI.unescape(ref)
2015-04-26 12:48:37 +05:30
result = CreateBranchService.new(project, current_user).
execute(branch_name, ref)
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
if result[:status] == :success
@branch = result[:branch]
redirect_to namespace_project_tree_path(@project.namespace, @project,
@branch.name)
else
@error = result[:message]
render action: 'new'
end
2014-09-02 18:07:02 +05:30
end
def destroy
2015-09-11 14:41:01 +05:30
@branch_name = Addressable::URI.unescape(params[:id])
status = DeleteBranchService.new(project, current_user).execute(@branch_name)
2014-09-02 18:07:02 +05:30
respond_to do |format|
2015-04-26 12:48:37 +05:30
format.html do
redirect_to namespace_project_branches_path(@project.namespace,
@project)
end
2015-09-11 14:41:01 +05:30
format.js { render status: status[:return_code] }
2014-09-02 18:07:02 +05:30
end
end
end