updates upstream merge to accept targeting branches other than master

parent c094ee14
......@@ -41,6 +41,13 @@ namespace :auto_deploy do
results.each do |result|
puts result.web_url
end
ReleaseTools::UpstreamMerge.new(
origin: ReleaseTools::Project::GitlabEe.remotes[:gitlab],
upstream: ReleaseTools::Project::GitlabCe.remotes[:gitlab],
source_branch: auto_deploy_branch,
target_branch: auto_deploy_branch
).dry_run
end
end
......
......@@ -21,7 +21,7 @@ module ReleaseTools
merge = UpstreamMerge.new(
origin: Project::GitlabEe.remotes[:gitlab],
upstream: Project::GitlabCe.remotes[:gitlab],
merge_branch: upstream_merge_request.source_branch
source_branch: upstream_merge_request.source_branch
)
upstream_merge_request.conflicts = merge.execute!
......
......@@ -2,17 +2,18 @@
module ReleaseTools
class UpstreamMerge
attr_reader :origin, :upstream, :merge_branch
attr_reader :origin, :upstream, :source_branch, :target_branch
CONFLICT_MARKER_REGEX = /\A(?<conflict_type>[ADU]{2}) /.freeze
DownstreamAlreadyUpToDate = Class.new(StandardError)
PushFailed = Class.new(StandardError)
def initialize(origin:, upstream:, merge_branch:)
def initialize(origin:, upstream:, source_branch:, target_branch: 'master')
@origin = origin
@upstream = upstream
@merge_branch = merge_branch
@source_branch = source_branch
@target_branch = target_branch
end
def execute!
......@@ -24,6 +25,11 @@ module ReleaseTools
conflicts
end
def dry_run
setup_merge_drivers
prepare_upstream_merge
end
private
def repository
......@@ -41,13 +47,13 @@ module ReleaseTools
def prepare_upstream_merge
$stdout.puts "Prepare repository...".colorize(:green)
# We fetch CE first to make sure our EE copy is more up-to-date!
repository.fetch('master', remote: :upstream)
repository.fetch('master', remote: :origin)
repository.checkout_new_branch(merge_branch, base: 'origin/master')
repository.fetch(target_branch, remote: :upstream)
repository.fetch(target_branch, remote: :origin)
repository.checkout_new_branch(source_branch, base: "origin/#{target_branch}")
end
def execute_upstream_merge
result = repository.merge('upstream/master', merge_branch, no_ff: true)
result = repository.merge("upstream/#{target_branch}", source_branch, no_ff: true)
# Depending on Git version, it's "up-to-date" or "up to date"...
raise DownstreamAlreadyUpToDate if result.output =~ /\AAlready up[\s\-]to[\s\-]date/
......@@ -61,7 +67,7 @@ module ReleaseTools
add_latest_modifier_to_conflicts(conflicts)
end
raise PushFailed unless repository.push(origin, merge_branch)
raise PushFailed unless repository.push(origin, source_branch)
conflicts
end
......
......@@ -20,7 +20,7 @@ describe ReleaseTools::Services::UpstreamMergeService do
.with(
origin: ReleaseTools::Project::GitlabEe.remotes[:gitlab],
upstream: ReleaseTools::Project::GitlabCe.remotes[:gitlab],
merge_branch: 'ce-to-ee-2017-11-15'
source_branch: 'ce-to-ee-2017-11-15'
).and_return(upstream_merge)
end
end
......
......@@ -16,7 +16,8 @@ describe ReleaseTools::UpstreamMerge, :silence_stdout, :aggregate_failures do
{
origin: ee_repo_url,
upstream: "file://#{ce_fixture.fixture_path}",
merge_branch: "ce-to-ee-#{SecureRandom.hex}"
source_branch: "ce-to-ee-#{SecureRandom.hex}",
target_branch: 'master'
}
end
let(:git_author_name) { 'Your Name' }
......@@ -53,12 +54,12 @@ describe ReleaseTools::UpstreamMerge, :silence_stdout, :aggregate_failures do
it 'creates a branch and merges upstream/master into it' do
subject.execute!
expect(ee_rugged_repo).to have_head(default_options[:merge_branch])
expect(ee_rugged_repo).to have_head(default_options[:source_branch])
expect(File.read(File.join(ee_repo_path, 'CONTRIBUTING.md'))).to eq('New CONTRIBUTING.md from CE')
expect(File.read(File.join(ee_repo_path, 'README.md'))).to eq('New README.md from EE')
expect(ee_rugged_repo).to have_commit_message <<~COMMIT_MESSAGE
Merge remote-tracking branch 'upstream/master' into #{default_options[:merge_branch]}
Merge remote-tracking branch 'upstream/master' into #{default_options[:source_branch]}
COMMIT_MESSAGE
end
end
......@@ -76,7 +77,7 @@ describe ReleaseTools::UpstreamMerge, :silence_stdout, :aggregate_failures do
it 'commits the conflicts and includes `[ci skip]` in the commit message' do
subject.execute!
expect(ee_rugged_repo).to have_head(default_options[:merge_branch])
expect(ee_rugged_repo).to have_head(default_options[:source_branch])
expect(File.read(File.join(ee_repo_path, 'README.md'))).to eq <<~CONTENT
<<<<<<< HEAD
New README.md from EE
......@@ -86,7 +87,7 @@ describe ReleaseTools::UpstreamMerge, :silence_stdout, :aggregate_failures do
CONTENT
expect(ee_rugged_repo).to have_commit_message <<~COMMIT_MESSAGE
Merge remote-tracking branch 'upstream/master' into #{default_options[:merge_branch]}
Merge remote-tracking branch 'upstream/master' into #{default_options[:source_branch]}
# Conflicts:
#\tREADME.md
......@@ -97,13 +98,13 @@ describe ReleaseTools::UpstreamMerge, :silence_stdout, :aggregate_failures do
end
it 'pushed the merge branch' do
expect(subject.__send__(:repository)).to receive(:push).with(ee_repo_url, default_options[:merge_branch]).and_return(true)
expect(subject.__send__(:repository)).to receive(:push).with(ee_repo_url, default_options[:source_branch]).and_return(true)
subject.execute!
end
it 'raises a PushError upon failure' do
expect(subject.__send__(:repository)).to receive(:push).with(ee_repo_url, default_options[:merge_branch]).and_return(false)
expect(subject.__send__(:repository)).to receive(:push).with(ee_repo_url, default_options[:source_branch]).and_return(false)
expect { subject.execute! }.to raise_error(described_class::PushFailed)
end
......@@ -113,7 +114,7 @@ describe ReleaseTools::UpstreamMerge, :silence_stdout, :aggregate_failures do
it 'raises a DownstreamAlreadyUpToDate error' do
expect { subject.execute! }.to raise_error(described_class::DownstreamAlreadyUpToDate)
expect(ee_rugged_repo).to have_head(default_options[:merge_branch])
expect(ee_rugged_repo).to have_head(default_options[:source_branch])
expect(File.read(File.join(ee_repo_path, 'CONTRIBUTING.md'))).to eq('Sample CONTRIBUTING.md')
expect(File.read(File.join(ee_repo_path, 'README.md'))).to eq('Sample README.md')
......
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