diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-01 15:45:42 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-01 15:45:42 +0000 |
commit | 459e6d346768d9d8fceaee00bf0870b8e7c4ed9a (patch) | |
tree | cdc959b40361be56eeac44b7ac19ef984fb7a62d | |
parent | 804168e1def1204af712febb229f41a3865f085f (diff) | |
parent | 2e6bbb12f86806ee13699f8cff03f13449105eb9 (diff) | |
download | gitlab-ce-459e6d346768d9d8fceaee00bf0870b8e7c4ed9a.tar.gz |
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
-rw-r--r-- | app/models/merge_request.rb | 8 | ||||
-rw-r--r-- | app/models/repository.rb | 9 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 14 |
3 files changed, 24 insertions, 7 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 040ab0f4b0f..53b3fc10ccb 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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 diff --git a/app/models/repository.rb b/app/models/repository.rb index 97d2aa1c89e..c767d1051d1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 77ceb6c8adc..a083dcb1274 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -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 |