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

69 lines
2.1 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
2016-09-13 17:45:13 +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, :destroy]
2014-09-02 18:07:02 +05:30
def index
2016-09-13 17:45:13 +05:30
@sort = params[:sort].presence || sort_value_name
2016-08-24 12:49:21 +05:30
@branches = BranchesFinder.new(@repository, params).execute
2016-06-02 11:05:42 +05:30
@branches = Kaminari.paginate_array(@branches).page(params[:page])
@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
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)
2016-06-02 11:05:42 +05:30
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
2016-06-02 11:05:42 +05:30
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
end
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,
2016-06-02 11:05:42 +05:30
@project), status: 303
2015-04-26 12:48:37 +05:30
end
format.js { render nothing: true, status: status[:return_code] }
2014-09-02 18:07:02 +05:30
end
end
2016-06-02 11:05:42 +05:30
private
def ref
if params[:ref]
ref_escaped = sanitize(strip_tags(params[:ref]))
Addressable::URI.unescape(ref_escaped)
else
@project.default_branch
end
end
2014-09-02 18:07:02 +05:30
end