This instance will be upgraded to Heptapod 0.31.0rc on 2022-05-19 at 11:00 UTC+2 (a few minutes of down time)

Commit 8779da45 authored by Douwe Maan's avatar Douwe Maan
Browse files

Don't show new MR URL after push when it doesn't make sense

parent 68785ca00dc8
......@@ -30,10 +30,21 @@ def opened_merge_requests_from_source_branches(branches)
end
def get_branches(changes)
return [] if project.empty_repo?
return [] unless project.merge_requests_enabled
changes_list = Gitlab::ChangesList.new(changes)
changes_list.map do |change|
next unless Gitlab::Git.branch_ref?(change[:ref])
Gitlab::Git.branch_name(change[:ref])
# Deleted branch
next if Gitlab::Git.blank_ref?(change[:newrev])
# Default branch
branch_name = Gitlab::Git.branch_name(change[:ref])
next if branch_name == project.default_branch
branch_name
end.compact
end
......
......@@ -7,7 +7,9 @@
let(:new_merge_request_url) { "http://localhost/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=#{source_branch}" }
let(:show_merge_request_url) { "http://localhost/#{project.namespace.name}/#{project.path}/merge_requests/#{merge_request.iid}" }
let(:new_branch_changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" }
let(:deleted_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 #{Gitlab::Git::BLANK_SHA} refs/heads/#{source_branch}" }
let(:existing_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" }
let(:default_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master" }
describe "#execute" do
shared_examples 'new_merge_request_link' do
......@@ -32,6 +34,28 @@
end
end
shared_examples 'no_merge_request_url' do
it 'returns no URL' do
result = service.execute(changes)
expect(result).to be_empty
end
end
context 'pushing to default branch' do
let(:changes) { default_branch_changes }
it_behaves_like 'no_merge_request_url'
end
context 'pushing to project with MRs disabled' do
let(:changes) { new_branch_changes }
before do
project.merge_requests_enabled = false
end
it_behaves_like 'no_merge_request_url'
end
context 'pushing one completely new branch' do
let(:changes) { new_branch_changes }
it_behaves_like 'new_merge_request_link'
......@@ -42,6 +66,11 @@
it_behaves_like 'new_merge_request_link'
end
context 'pushing to deleted branch' do
let(:changes) { deleted_branch_changes }
it_behaves_like 'no_merge_request_url'
end
context 'pushing to existing branch and merge request opened' do
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch) }
let(:changes) { existing_branch_changes }
......@@ -61,6 +90,11 @@
let(:changes) { existing_branch_changes }
# Source project is now the forked one
let(:service) { MergeRequests::GetUrlsService.new(forked_project) }
before do
allow(forked_project).to receive(:empty_repo?).and_return(false)
end
it_behaves_like 'show_merge_request_url'
end
......
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