use CI variable to determine which branch to pick into

parent 53dc35b6
......@@ -16,24 +16,25 @@ namespace :auto_deploy do
desc 'Pick commits into the auto deploy branches'
task :pick do
operating_branch_info = ReleaseTools::Services::AutoDeployBranchService.new(nil).filter_branches
version = ReleaseTools::Version.new(operating_branch_info[:version]).to_ee
auto_deploy_branch = ENV['AUTO_DEPLOY_BRANCH']
abort('AUTO_DEPLOY_BRANCH must be set for this rake task'.colorize(:red)) unless auto_deploy_branch
puts "We'll pick into #{auto_deploy_branch}"
scrub_version = auto_deploy_branch.match(/^(\d+-\d+)-auto-deploy-(\d+)-ee$/)[1].tr('-', '.')
version = ReleaseTools::Version.new(scrub_version).to_ee
$stdout.puts "--> Picking for #{version}..."
results = ReleaseTools::CherryPick::Service
.new(ReleaseTools::Project::GitlabEe, version, operating_branch_info[:branch])
.new(ReleaseTools::Project::GitlabEe, version, auto_deploy_branch)
.dry_run
$stdout.puts "Nothing to pick." if results.empty?
exit 1 if results.empty?
binding.pry
results = ReleaseTools::CherryPick::Service
.new(ReleaseTools::Project::GitlabEe, version, operating_branch_info[:branch])
.execute
if results.empty?
$stdout.puts "Nothing to pick."
exit 1
end
results.each do |result|
puts result.inspect
puts result.web_url
end
end
end
......
......@@ -29,17 +29,9 @@ module ReleaseTools
end
def filter_branches
versions = []
puts "Getting available branches..."
versions = available_branches || branches
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$/)
branch_name = branch.name
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
latest_version = []
versions.each do |v|
......@@ -60,6 +52,25 @@ module ReleaseTools
private
def version
@version ||= gitlab_client.current_milestone.title.tr('.', '-')
end
def available_branches
Struct.new("Version", :version, :pipeline_id, :branch_name)
puts "finding available branches..."
ReleaseTools::GitlabClient.protected_branches(ReleaseTools::Project::GitlabEe.path).auto_paginate.each do |branch|
puts branch.name
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('-', '.')
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
end
def update_auto_deploy_ci
gitlab_client.update_variable(Project::ReleaseTools.path, CI_VAR_AUTO_DEPLOY, branch_name)
rescue Gitlab::Error::NotFound
......
......@@ -50,14 +50,14 @@ describe ReleaseTools::Services::AutoDeployBranchService do
end
end
end
end
describe ReleaseTools::Services::AutoDeployBranchService do
describe '#filter_branches' do
subject(:service) do
VCR.use_cassette('branches/list') do
wut = described_class.new(1)
wut.filter_branches
let(:branches) { double(version: "11.10") }
subject(:filter_branches) do
VCR.use_cassette('milestones/active') do
described_class.new('9000')
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