Commit e49030cf authored by Sean McGivern's avatar Sean McGivern

Merge branch 'improve-ee_specific_check' into 'master'

Improve ee specific check

See merge request gitlab-org/gitlab-ee!7859
parents 459245d3 c93db5d2
......@@ -277,7 +277,9 @@ module EESpecificCheck
def matching_ce_refs
@matching_ce_refs ||=
run_git_command("ls-remote #{ce_repo_url} \"*#{minimal_ce_branch_name}*\"")
.scan(%r{(?<=refs/heads/|refs/tags/).+}).sort_by(&:size)
.scan(%r{(?<=refs/heads/|refs/tags/).+})
.select { |branch| branch.match?(/\b#{minimal_ce_branch_name}\b/i) }
.sort_by(&:size)
end
def scan_diff_numstat(numstat)
......@@ -312,47 +314,105 @@ if $0 == __FILE__
require 'rspec/autorun'
RSpec.describe EESpecificCheck do
subject { Class.new { include EESpecificCheck }.new }
before do
extend EESpecificCheck
allow(subject).to receive(:warn)
allow(self).to receive(:warn)
EESpecificCheck.private_instance_methods.each do |name|
subject.class.__send__(:public, name) # rubocop:disable GitlabSecurity/PublicSend
end
end
describe '.run_git_command' do
# rubocop: disable CodeReuse/ActiveRecord
it 'returns the single output when there is a single command' do
output = run_git_command('status')
output = subject.run_git_command('status')
expect(output).to be_kind_of(String)
expect(self).to have_received(:warn).with(/git status/)
expect(subject).to have_received(:warn).with(/git status/)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
it 'returns an array of output for more commands' do
output = run_git_command('status', 'help')
output = subject.run_git_command('status', 'help')
expect(output).to all(be_a(String))
expect(self).to have_received(:warn).with(/git status/)
expect(self).to have_received(:warn).with(/git help/)
expect(subject).to have_received(:warn).with(/git status/)
expect(subject).to have_received(:warn).with(/git help/)
end
# rubocop: enable CodeReuse/ActiveRecord
end
describe '.matching_ce_refs' do
before do
expect(self).to receive(:current_branch).and_return('v9')
expect(self).to receive(:run_git_command)
.and_return(<<~OUTPUT)
expect(subject).to receive(:current_branch).and_return(ee_branch)
expect(subject).to receive(:run_git_command)
.and_return(ls_remote_output)
end
describe 'simple cases' do
let(:ls_remote_output) do
<<~OUTPUT
d6602ec5194c87b0fc87103ca4d67251c76f233a\trefs/tags/v9
f25a265a342aed6041ab0cc484224d9ca54b6f41\trefs/tags/v9.12
c5db5456ae3b0873fc659c19fafdde22313cc441\trefs/tags/v9.123
0918385dbd9656cab0d1d81ba7453d49bbc16250\trefs/heads/v9.x
28862662b749fe981386814e2dba87b0e72c1eab\trefs/remotes/remote_mirror_3059/v9-to-fix-http-case-problems
5e3496802098c86050c5b463507f3a68a83a9f02\trefs/remotes/remote_mirror_3059/29036-use-slack-service-v9
OUTPUT
end
context 'with a ee- prefix' do
let(:ee_branch) { 'ee-v9' }
it 'sorts by matching size' do
expect(subject.matching_ce_refs).to eq(%w[v9 v9.x v9.12 v9.123])
end
end
context 'with a -ee suffix' do
let(:ee_branch) { 'v9-ee' }
it 'sorts by matching size' do
expect(subject.matching_ce_refs).to eq(%w[v9 v9.x v9.12 v9.123])
end
end
end
describe 'with ambiguous branch name' do
let(:ls_remote_output) do
<<~OUTPUT
954d7119384c9f2a3c862bac97beb641eb8755d6\trefs/heads/feature/sm/35954-expand-kubernetesservice-to-use-username-password
954d7119384c9f2a3c862bac97beb641eb8755d6\trefs/heads/ce-to-ee-231
954d7119384c9f2a3c862bac97beb641eb8755d6\trefs/heads/ce-to-ee-2
954d7119384c9f2a3c862bac97beb641eb8755d6\trefs/heads/ce-to-1
954d7119384c9f2a3c862bac97beb641eb8755d6\trefs/heads/ee-to-ce-123
954d7119384c9f2a3c862bac97beb641eb8755d6\trefs/heads/ee-to-ce-12
954d7119384c9f2a3c862bac97beb641eb8755d6\trefs/heads/to-ce-1
28862662b749fe981386814e2dba87b0e72c1eab\trefs/remotes/remote_mirror_3059/27056-upgrade-vue-resource-to-1-0-3-to-fix-http-case-problems
5e3496802098c86050c5b463507f3a68a83a9f02\trefs/remotes/remote_mirror_3059/29036-use-slack-service-to-notify-of-failed-pipelines
OUTPUT
end
context 'with a ee- prefix' do
let(:ee_branch) { 'ee-to-ce' }
let(:minimal_ce_branch) { 'to-ce' }
it 'sorts by matching size' do
expect(matching_ce_refs).to eq(%w[v9 v9.x v9.12 v9.123])
expect(subject.matching_ce_refs).to eq(%w[to-ce-1 ee-to-ce-12 ee-to-ce-123])
end
end
context 'with a -ee suffix' do
let(:ee_branch) { 'ce-to-ee' }
let(:minimal_ce_branch) { 'ce-to' }
it 'sorts by matching size' do
expect(subject.matching_ce_refs).to eq(%w[ce-to-1 ce-to-ee-2 ce-to-ee-231])
end
end
end
end
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