[refs #90] small controller refactoring
This commit is contained in:
parent
94029c3cda
commit
bf7bc8787a
|
@ -8,14 +8,14 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
load_and_authorize_resource :instance_name => :pull, :through => :issue, :singleton => true, :except => [:index, :autocomplete_to_project]
|
load_and_authorize_resource :instance_name => :pull, :through => :issue, :singleton => true, :except => [:index, :autocomplete_to_project]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
to_project = set_to_project(false)
|
to_project = find_destination_project(false)
|
||||||
authorize! :read, to_project
|
authorize! :read, to_project
|
||||||
|
|
||||||
@pull = to_project.pull_requests.new
|
@pull = to_project.pull_requests.new
|
||||||
@pull.issue = to_project.issues.new
|
@pull.issue = to_project.issues.new
|
||||||
set_attrs
|
set_attrs
|
||||||
|
|
||||||
if PullRequest.check_ref(@pull, 'base', @pull.to_ref) && PullRequest.check_ref(@pull, 'head', @pull.from_ref) || @pull.uniq_merge
|
if PullRequest.check_ref(@pull, 'to', @pull.to_ref) && PullRequest.check_ref(@pull, 'from', @pull.from_ref) || @pull.uniq_merge
|
||||||
flash.now[:warning] = @pull.errors.full_messages.join('. ')
|
flash.now[:warning] = @pull.errors.full_messages.join('. ')
|
||||||
else
|
else
|
||||||
@pull.check(false) # don't make event transaction
|
@pull.check(false) # don't make event transaction
|
||||||
|
@ -33,7 +33,7 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
raise 'expect pull_request params' # for debug
|
raise 'expect pull_request params' # for debug
|
||||||
redirect :back
|
redirect :back
|
||||||
end
|
end
|
||||||
to_project = set_to_project
|
to_project = find_destination_project
|
||||||
authorize! :read, to_project
|
authorize! :read, to_project
|
||||||
|
|
||||||
@pull = to_project.pull_requests.new pull_params
|
@pull = to_project.pull_requests.new pull_params
|
||||||
|
@ -140,15 +140,11 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
@stats = @pull.diff_stats repo, @base_commit, @head_commit
|
@stats = @pull.diff_stats repo, @base_commit, @head_commit
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_to_project bang=true
|
def find_destination_project bang=true
|
||||||
args = params[:to_project].try(:split, '/') || []
|
args = params[:to_project].try(:split, '/') || []
|
||||||
if bang
|
project = (args.length == 2) ? Project.find_by_owner_and_name(*args) : nil
|
||||||
raise ActiveRecord::RecordNotFound if args.length != 2
|
raise ActiveRecord::RecordNotFound if bang && !project
|
||||||
Project.find_by_owner_and_name! *args
|
project.try(:parent) || @project
|
||||||
else
|
|
||||||
return @project.parent || @project.root if args.length != 2
|
|
||||||
Project.find_by_owner_and_name(*args) || @project.parent || @project.root
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_attrs
|
def set_attrs
|
||||||
|
|
Loading…
Reference in New Issue