Unverified Commit eed377d6 authored by John Skarbek's avatar John Skarbek Committed by John Skarbek

complete logic to find the latest branch to operate on

parent bac89d77
......@@ -16,32 +16,16 @@ namespace :auto_deploy do
desc 'Pick commits into the auto deploy branches'
task :pick do
versions = {}
count = 0
ReleaseTools::GitlabClient.branches(ReleaseTools::Project::GitlabEe.path).auto_paginate.each do |branch|
if branch.name =~ /^(\d+-\d+)-auto-deploy-\d+-ee$/
#binding.pry
# convert the version to version used for picking
branch_name = branch.name
version = branch.name.match(/^(\d+-\d+)-auto-deploy-\d+-ee$/)[1].gsub('-', '.')
versions.merge!(branch_name => version)
count += 1
end
end
puts count
puts versions.count
versions.each do |branch_name, version|
version = ReleaseTools::Version.new(version).to_ee
puts "--> Picking for #{version}..."
results = ReleaseTools::CherryPick::Service
.new(ReleaseTools::Project::GitlabEe, version, branch_name)
.dry_run
binding.pry
results.each do |result|
puts result.inspect
end
operating_branch_info = ReleaseTools::Services::AutoDeployBranchService.new(nil).filter_branches
binding.pry
version = ReleaseTools::Version.new(operating_branch_info[:version]).to_ee
puts "--> Picking for #{version}..."
results = ReleaseTools::CherryPick::Service
.new(ReleaseTools::Project::GitlabEe, version, operating_branch_info[:branch])
.dry_run
results.each do |result|
puts result.inspect
end
# check for valid pick tag that contains version
......
......@@ -29,15 +29,33 @@ module ReleaseTools
end
def filter_branches
versions = {}
versions = []
Struct.new("Version", :version, :pipeline_id, :branch_name)
ReleaseTools::GitlabClient.branches(ReleaseTools::Project::GitlabEe.path).auto_paginate.each do |branch|
next unless branch.name.match?(/^(\d+-\d+)-auto-deploy-\d+-ee$/)
next unless branch.name.match?(/^\d+-\d+-auto-deploy-\d+-ee$/)
branch_name = branch.name
version = branch.name.match(/^(\d+-\d+)-auto-deploy-\d+-ee$/)[1].tr('-', '.')
versions.merge!(branch_name => version)
version = branch.name.match(/^(\d+-\d+)-auto-deploy-(\d+)-ee$/)[1].tr('-', '.')
pipeline_id = branch.name.match(/^(\d+-\d+)-auto-deploy-(\d+)-ee$/)[2]
version_data = Struct::Version.new(version, pipeline_id, branch_name)
versions << version_data
end
versions
latest_version = []
versions.each do |v|
latest_version << v.version
end
latest_version.uniq!
latest_version = VersionSorter.rsort(latest_version).first
pipelines = []
versions.each do |v|
pipelines << v.pipeline_id if v.version == latest_version
end
branch = versions.find { |struct| struct.version == latest_version && struct.pipeline_id == pipelines.sort.reverse.first }.branch_name
{ version: latest_version, branch: branch }
end
private
......
......@@ -62,7 +62,7 @@ describe ReleaseTools::Services::AutoDeployBranchService do
end
it 'finds all auto-deploy branches' do
expect(subject).to be_nil
expect(subject).to eq(version: "11.11", branch: "11-11-auto-deploy-0900001-ee")
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