Merge branch 'refactor-can-be-merge' into 'master'
Refactor can_be_merged logic for merge request Some refactoring after !918 cc @DouweM @rspeicher Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> See merge request !919
This commit is contained in:
commit
459e6d3467
3 changed files with 24 additions and 7 deletions
|
@ -209,13 +209,7 @@ class MergeRequest < ActiveRecord::Base
|
|||
if for_fork?
|
||||
Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
|
||||
else
|
||||
rugged = project.repository.rugged
|
||||
our_commit = rugged.branches[target_branch].target
|
||||
their_commit = rugged.branches[source_branch].target
|
||||
|
||||
if our_commit && their_commit
|
||||
!rugged.merge_commits(our_commit, their_commit).conflicts?
|
||||
end
|
||||
project.repository.can_be_merged?(source_branch, target_branch)
|
||||
end
|
||||
|
||||
if can_be_merged
|
||||
|
|
|
@ -422,6 +422,15 @@ class Repository
|
|||
}
|
||||
end
|
||||
|
||||
def can_be_merged?(source_branch, target_branch)
|
||||
our_commit = rugged.branches[target_branch].target
|
||||
their_commit = rugged.branches[source_branch].target
|
||||
|
||||
if our_commit && their_commit
|
||||
!rugged.merge_commits(our_commit, their_commit).conflicts?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cache
|
||||
|
|
|
@ -33,4 +33,18 @@ describe Repository do
|
|||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe :can_be_merged? do
|
||||
context 'mergeable branches' do
|
||||
subject { repository.can_be_merged?('feature', 'master') }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'non-mergeable branches' do
|
||||
subject { repository.can_be_merged?('feature_conflict', 'feature') }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue