Refactor some code
This commit is contained in:
parent
4a0cf269a6
commit
ce35dcbc81
|
@ -38,8 +38,8 @@ module Gitlab
|
|||
|
||||
def source_branch_name
|
||||
@source_branch_name ||= begin
|
||||
if source_branch.repo.id != target_branch.repo.id
|
||||
"pull/#{number}/#{source_branch.repo.full_name}/#{source_branch_ref}"
|
||||
if cross_project?
|
||||
"pull/#{number}/#{source_branch_repo.full_name}/#{source_branch_ref}"
|
||||
else
|
||||
source_branch_exists? ? source_branch_ref : "pull/#{number}/#{source_branch_ref}"
|
||||
end
|
||||
|
@ -56,6 +56,10 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
def cross_project?
|
||||
source_branch.repo.id != target_branch.repo.id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def state
|
||||
|
|
|
@ -281,6 +281,24 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#cross_project?' do
|
||||
context 'when source and target repositories are different' do
|
||||
let(:raw_data) { double(base_data.merge(head: forked_branch)) }
|
||||
|
||||
it 'returns true' do
|
||||
expect(pull_request.cross_project?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when source and target repositories are the same' do
|
||||
let(:raw_data) { double(base_data.merge(head: source_branch)) }
|
||||
|
||||
it 'returns false' do
|
||||
expect(pull_request.cross_project?).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#url' do
|
||||
let(:raw_data) { double(base_data) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue