[refs #90] try to prevent create same pull
This commit is contained in:
parent
6b6887250b
commit
d643bb3cd0
|
@ -10,7 +10,6 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@pull = PullRequest.default_base_project(@project).pull_requests.new
|
@pull = PullRequest.default_base_project(@project).pull_requests.new
|
||||||
FileUtils.rm_rf @pull.path
|
|
||||||
#@pull.build_issue
|
#@pull.build_issue
|
||||||
@pull.issue = @project.issues.new
|
@pull.issue = @project.issues.new
|
||||||
@pull.head_project = @project
|
@pull.head_project = @project
|
||||||
|
|
|
@ -8,7 +8,10 @@ class PullRequest < ActiveRecord::Base
|
||||||
delegate :user, :title, :body, :serial_id, :assignee, :state, :to => :issue, :allow_nil => true
|
delegate :user, :title, :body, :serial_id, :assignee, :state, :to => :issue, :allow_nil => true
|
||||||
accepts_nested_attributes_for :issue
|
accepts_nested_attributes_for :issue
|
||||||
#attr_accessible #FIXME disable for development
|
#attr_accessible #FIXME disable for development
|
||||||
scope :needed_checking, where(:state => ['open', 'blocked', 'ready'])
|
#validate :uniq_merge
|
||||||
|
before_create :clean_dir
|
||||||
|
|
||||||
|
scope :needed_checking, includes(:issue).where(:issues => {:state => ['open', 'blocked', 'ready', 'already']})
|
||||||
|
|
||||||
state_machine :initial => :open do
|
state_machine :initial => :open do
|
||||||
#after_transition [:ready, :blocked] => [:merged, :closed] do |pull, transition|
|
#after_transition [:ready, :blocked] => [:merged, :closed] do |pull, transition|
|
||||||
|
@ -79,19 +82,6 @@ class PullRequest < ActiveRecord::Base
|
||||||
project.is_root? ? project : project.root
|
project.is_root? ? project : project.root
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean #FIXME move to protected
|
|
||||||
Dir.chdir(path) do
|
|
||||||
base_project.branches.each {|branch| system 'git', 'checkout', branch.name}
|
|
||||||
system 'git', 'checkout', base_ref
|
|
||||||
|
|
||||||
base_project.branches.each do |branch|
|
|
||||||
system 'git', 'branch', '-D', branch.name unless [base_ref, head_branch].include? branch.name
|
|
||||||
end
|
|
||||||
base_project.tags.each do |tag|
|
|
||||||
system 'git', 'tag', '-d', tag.name unless [base_ref, head_branch].include? tag.name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def path
|
def path
|
||||||
filename = [id, base_ref, head_project.owner.uname, head_project.name, head_ref].compact.join('-')
|
filename = [id, base_ref, head_project.owner.uname, head_project.name, head_ref].compact.join('-')
|
||||||
|
@ -143,4 +133,28 @@ class PullRequest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
# TODO catch errors
|
# TODO catch errors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clean
|
||||||
|
Dir.chdir(path) do
|
||||||
|
base_project.branches.each {|branch| system 'git', 'checkout', branch.name}
|
||||||
|
system 'git', 'checkout', base_ref
|
||||||
|
|
||||||
|
base_project.branches.each do |branch|
|
||||||
|
system 'git', 'branch', '-D', branch.name unless [base_ref, head_branch].include? branch.name
|
||||||
|
end
|
||||||
|
base_project.tags.each do |tag|
|
||||||
|
system 'git', 'tag', '-d', tag.name unless [base_ref, head_branch].include? tag.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def uniq_merge
|
||||||
|
if base_project.pull_requests.needed_checking.where('pull_requests.id != ?', id).count >= 1
|
||||||
|
errors.add(:head_ref, t('projects.pull_requests.duplicate', :head_ref => head_ref))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean_dir
|
||||||
|
FileUtils.rm_rf path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,11 @@
|
||||||
.leftlist=issue.label :title, t('activerecord.attributes.issue.body'), :class => :label
|
.leftlist=issue.label :title, t('activerecord.attributes.issue.body'), :class => :label
|
||||||
.rightlist=issue.text_area :body
|
.rightlist=issue.text_area :body
|
||||||
.both
|
.both
|
||||||
|
|
||||||
|
.leftlist for debug
|
||||||
|
.rightlist=@pull.state
|
||||||
|
.both
|
||||||
|
|
||||||
.leftlist
|
.leftlist
|
||||||
\
|
\
|
||||||
.rightlist=f.submit t('.submit'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing'), :id => 'create_pull'
|
.rightlist=f.submit t('.submit'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing'), :id => 'create_pull'
|
||||||
|
|
|
@ -3,13 +3,14 @@ en:
|
||||||
pull_requests:
|
pull_requests:
|
||||||
new:
|
new:
|
||||||
new: 'Create a pull request into <span class="label label-info font14">%{base}</span> from <span class="label label-info font14">%{head}</span>'
|
new: 'Create a pull request into <span class="label label-info font14">%{base}</span> from <span class="label label-info font14">%{head}</span>'
|
||||||
base_ref: 'Base'
|
base_ref: Base
|
||||||
head_ref: 'Head'
|
head_ref: Head
|
||||||
refs: 'branch · tag · commit'
|
refs: 'branch · tag · commit'
|
||||||
base_project: 'Base project'
|
base_project: Base project
|
||||||
head_project: 'Head project'
|
head_project: Head project
|
||||||
submit: 'Send pull request'
|
submit: Send pull request
|
||||||
merge: Merge
|
merge: Merge
|
||||||
|
duplicate: There's already a pull request for %{head_ref}
|
||||||
|
|
||||||
pull_requests:
|
pull_requests:
|
||||||
tabs:
|
tabs:
|
||||||
|
|
|
@ -3,13 +3,14 @@ ru:
|
||||||
pull_requests:
|
pull_requests:
|
||||||
new:
|
new:
|
||||||
new: 'Создать запрос на слияние в <span class="label label-info font14">%{base}</span> из <span class="label label-info font14">%{head}</span>'
|
new: 'Создать запрос на слияние в <span class="label label-info font14">%{base}</span> из <span class="label label-info font14">%{head}</span>'
|
||||||
base_ref: 'База'
|
base_ref: База
|
||||||
head_ref: 'Источник'
|
head_ref: Источник
|
||||||
refs: 'branch · tag · commit'
|
refs: 'branch · tag · commit'
|
||||||
base_project: 'Базовый проект'
|
base_project: Базовый проект
|
||||||
head_project: 'Проект-источник'
|
head_project: Проект-источник
|
||||||
submit: 'Создать запрос на слияние'
|
submit: Создать запрос на слияние
|
||||||
merge: Слияние
|
merge: Слияние
|
||||||
|
duplicate: Уже существует запрос на слияние %{head_ref}
|
||||||
|
|
||||||
pull_requests:
|
pull_requests:
|
||||||
tabs:
|
tabs:
|
||||||
|
|
|
@ -23,7 +23,7 @@ describe PullRequest do
|
||||||
|
|
||||||
context 'for owner user' do
|
context 'for owner user' do
|
||||||
before (:all) do
|
before (:all) do
|
||||||
stub_rsync_methods
|
stub_symlink_methods
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
set_data_for_pull
|
set_data_for_pull
|
||||||
@pull = @project.pull_requests.new(:issue_attributes => {:title => 'test', :body => 'testing'})
|
@pull = @project.pull_requests.new(:issue_attributes => {:title => 'test', :body => 'testing'})
|
||||||
|
@ -74,10 +74,20 @@ describe PullRequest do
|
||||||
@other_pull.state.should == 'already'
|
@other_pull.state.should == 'already'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not be created same pull" do
|
||||||
|
@same_pull = @project.pull_requests.new(:issue_attributes => {:title => 'same', :body => 'testing'})
|
||||||
|
@same_pull.issue.user, @same_pull.issue.project = @user, @same_pull.base_project
|
||||||
|
@same_pull.base_ref = 'master'
|
||||||
|
@same_pull.head_project, @same_pull.head_ref = @project, 'non_conflicts'
|
||||||
|
@same_pull.save
|
||||||
|
@project.pull_requests.includes(:issue).where(:issues => {:title => @same_pull.title}).count.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
before(:all) do
|
before(:all) do
|
||||||
stub_rsync_methods
|
stub_symlink_methods
|
||||||
Platform.delete_all
|
Platform.delete_all
|
||||||
User.delete_all
|
User.delete_all
|
||||||
Repository.delete_all
|
Repository.delete_all
|
||||||
|
|
Loading…
Reference in New Issue