summaryrefslogtreecommitdiff
path: root/bin/secpick
diff options
context:
space:
mode:
authorJames Lopez <james@gitlab.com>2018-04-17 16:50:16 +0000
committerMarin Jankovski <marin@gitlab.com>2018-04-17 16:50:16 +0000
commit22e198dae1ead0971befadd7950ee2eadecb242f (patch)
treeb9bd92804b013af65d1ad4c7233db6a01b06884e /bin/secpick
parenta6486f763387f5d91b73d59e990b999c89a03fc3 (diff)
downloadgitlab-ce-22e198dae1ead0971befadd7950ee2eadecb242f.tar.gz
add initial dev task template for working on a security issue
Diffstat (limited to 'bin/secpick')
-rwxr-xr-xbin/secpick47
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/secpick b/bin/secpick
new file mode 100755
index 00000000000..76ae231e913
--- /dev/null
+++ b/bin/secpick
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+require 'optparse'
+require 'open3'
+require 'rainbow/refinement'
+using Rainbow
+
+BRANCH_PREFIX = 'security'.freeze
+STABLE_BRANCH_SUFFIX = 'stable'.freeze
+REMOTE = 'dev'.freeze
+
+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
+
+ opts.on('-b', '--branch security-fix-branch', 'Original branch name') do |branch|
+ 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!
+
+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/
+
+branch = [BRANCH_PREFIX, options[:branch], options[:version]].join('-').freeze
+stable_branch = "#{options[:version]}-#{STABLE_BRANCH_SUFFIX}".freeze
+
+command = "git checkout #{stable_branch} && git pull #{REMOTE} #{stable_branch} && git checkout -B #{branch} && git cherry-pick #{options[:sha]} && git push #{REMOTE} #{branch}"
+
+_stdin, stdout, stderr = Open3.popen3(command)
+
+puts stdout.read&.green
+puts stderr.read&.red