2018-04-17 12:50:16 -04:00
|
|
|
#!/usr/bin/env ruby
|
2018-12-18 04:21:29 -05:00
|
|
|
# frozen_string_literal: false
|
|
|
|
|
|
|
|
require 'active_support/core_ext/object/to_query'
|
2018-04-17 12:50:16 -04:00
|
|
|
require 'optparse'
|
|
|
|
require 'open3'
|
|
|
|
require 'rainbow/refinement'
|
|
|
|
using Rainbow
|
|
|
|
|
|
|
|
BRANCH_PREFIX = 'security'.freeze
|
|
|
|
REMOTE = 'dev'.freeze
|
2018-12-18 04:21:29 -05:00
|
|
|
NEW_MR_URL = 'https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/new'.freeze
|
2018-04-17 12:50:16 -04:00
|
|
|
|
|
|
|
options = { version: nil, branch: nil, sha: nil }
|
|
|
|
|
|
|
|
parser = OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: #{$0} [options]"
|
|
|
|
opts.on('-v', '--version 10.0', 'Version') do |version|
|
|
|
|
options[:version] = version&.tr('.', '-')
|
|
|
|
end
|
|
|
|
|
2018-10-24 13:20:03 -04:00
|
|
|
opts.on('-b', '--branch security-fix-branch', 'Original branch name (optional, defaults to current)') do |branch|
|
2018-04-17 12:50:16 -04:00
|
|
|
options[:branch] = branch
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on('-s', '--sha abcd', 'SHA to cherry pick') do |sha|
|
|
|
|
options[:sha] = sha
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on('-h', '--help', 'Displays Help') do
|
|
|
|
puts opts
|
|
|
|
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.parse!
|
|
|
|
|
2018-10-24 13:20:03 -04:00
|
|
|
options[:branch] ||= `git rev-parse --abbrev-ref HEAD`
|
|
|
|
|
2018-04-17 12:50:16 -04:00
|
|
|
abort("Missing options. Use #{$0} --help to see the list of options available".red) if options.values.include?(nil)
|
|
|
|
abort("Wrong version format #{options[:version].bold}".red) unless options[:version] =~ /\A\d*\-\d*\Z/
|
|
|
|
|
2018-10-24 13:20:03 -04:00
|
|
|
ee = File.exist?('./CHANGELOG-EE.md')
|
|
|
|
original_branch = options[:branch].strip
|
|
|
|
branch = "#{original_branch}-#{options[:version]}"
|
2018-08-15 03:27:59 -04:00
|
|
|
branch.prepend("#{BRANCH_PREFIX}-") unless branch.start_with?("#{BRANCH_PREFIX}-")
|
|
|
|
branch = branch.freeze
|
2018-10-24 13:20:03 -04:00
|
|
|
stable_branch = "#{BRANCH_PREFIX}-#{options[:version]}".tap do |name|
|
|
|
|
name << "-ee" if ee
|
|
|
|
end.freeze
|
2018-04-17 12:50:16 -04:00
|
|
|
|
2018-10-24 13:20:03 -04:00
|
|
|
command = "git fetch #{REMOTE} #{stable_branch} && git checkout #{stable_branch} && git pull #{REMOTE} #{stable_branch} && git checkout -B #{branch} && git cherry-pick #{options[:sha]} && git push #{REMOTE} #{branch} && git checkout #{original_branch}"
|
2018-04-17 12:50:16 -04:00
|
|
|
|
2018-12-18 04:21:29 -05:00
|
|
|
stdin, stdout, stderr, wait_thr = Open3.popen3(command)
|
2018-04-17 12:50:16 -04:00
|
|
|
|
|
|
|
puts stdout.read&.green
|
|
|
|
puts stderr.read&.red
|
2018-12-18 04:21:29 -05:00
|
|
|
|
|
|
|
if wait_thr.value.success?
|
|
|
|
params = {
|
|
|
|
merge_request: {
|
|
|
|
source_branch: branch,
|
|
|
|
target_branch: stable_branch,
|
|
|
|
title: "WIP: [#{options[:version].tr('-', '.')}] ",
|
|
|
|
description: '/label ~security'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
puts "#{NEW_MR_URL}?#{params.to_query}".blue
|
|
|
|
end
|
|
|
|
|
|
|
|
stdin.close
|
|
|
|
stdout.close
|
|
|
|
stderr.close
|