gitlab-org--gitlab-foss/app/controllers/projects/branches_controller.rb

68 lines
2.1 KiB
Ruby
Raw Normal View History

class Projects::BranchesController < Projects::ApplicationController
2014-11-13 10:20:43 -05:00
include ActionView::Helpers::SanitizeHelper
# Authorize
before_action :require_non_empty_project
before_action :authorize_download_code!
before_action :authorize_push_code!, only: [:new, :create, :destroy]
def index
@sort = params[:sort].presence || 'name'
@branches = BranchesFinder.new(@repository, params).execute
@branches = Kaminari.paginate_array(@branches).page(params[:page])
2016-02-12 13:42:25 -05:00
2015-11-11 17:29:29 -05:00
@max_commits = @branches.reduce(0) do |memo, branch|
diverging_commit_counts = repository.diverging_commit_counts(branch)
[memo, diverging_commit_counts[:behind], diverging_commit_counts[:ahead]].max
end
end
2013-08-05 10:59:58 -04:00
def recent
@branches = @repository.recent_branches
end
def create
2014-11-13 10:20:43 -05:00
branch_name = sanitize(strip_tags(params[:branch_name]))
branch_name = Addressable::URI.unescape(branch_name)
2016-02-12 13:42:25 -05:00
result = CreateBranchService.new(project, current_user).
2014-11-13 10:20:43 -05:00
execute(branch_name, ref)
2016-02-22 03:20:04 -05:00
if params[:issue_iid]
issue = @project.issues.find_by(iid: params[:issue_iid])
SystemNoteService.new_issue_branch(issue, @project, current_user, branch_name) if issue
2016-02-17 01:11:48 -05:00
end
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
end
def destroy
@branch_name = Addressable::URI.unescape(params[:id])
status = DeleteBranchService.new(project, current_user).execute(@branch_name)
respond_to do |format|
format.html do
redirect_to namespace_project_branches_path(@project.namespace,
@project), status: 303
end
format.js { render nothing: true, status: status[:return_code] }
end
end
2016-02-12 13:42:25 -05:00
private
def ref
if params[:ref]
ref_escaped = sanitize(strip_tags(params[:ref]))
Addressable::URI.unescape(ref_escaped)
else
@project.default_branch
end
end
end