Commit ce35dcbc authored by Gabriel Mazetto's avatar Gabriel Mazetto

Refactor some code

parent 4a0cf269
...@@ -38,8 +38,8 @@ module Gitlab ...@@ -38,8 +38,8 @@ module Gitlab
def source_branch_name def source_branch_name
@source_branch_name ||= begin @source_branch_name ||= begin
if source_branch.repo.id != target_branch.repo.id if cross_project?
"pull/#{number}/#{source_branch.repo.full_name}/#{source_branch_ref}" "pull/#{number}/#{source_branch_repo.full_name}/#{source_branch_ref}"
else else
source_branch_exists? ? source_branch_ref : "pull/#{number}/#{source_branch_ref}" source_branch_exists? ? source_branch_ref : "pull/#{number}/#{source_branch_ref}"
end end
...@@ -56,6 +56,10 @@ module Gitlab ...@@ -56,6 +56,10 @@ module Gitlab
end end
end end
def cross_project?
source_branch.repo.id != target_branch.repo.id
end
private private
def state def state
......
...@@ -281,6 +281,24 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -281,6 +281,24 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end end
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 describe '#url' do
let(:raw_data) { double(base_data) } let(:raw_data) { double(base_data) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment