Commit 1a2b9e31 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix Rubocop offenses in bin/secpick script

parent ab714baf
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: false # frozen_string_literal: false
require 'active_support/core_ext/object/to_query' require 'active_support/core_ext/object/to_query'
...@@ -7,52 +8,14 @@ require 'open3' ...@@ -7,52 +8,14 @@ require 'open3'
require 'rainbow/refinement' require 'rainbow/refinement'
using Rainbow using Rainbow
BRANCH_PREFIX = 'security'.freeze module Secpick
DEFAULT_REMOTE = 'dev'.freeze BRANCH_PREFIX = 'security'.freeze
NEW_MR_URL = 'https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/new'.freeze DEFAULT_REMOTE = 'dev'.freeze
NEW_MR_URL = 'https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/new'.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 (optional, defaults to current)') do |branch|
options[:branch] = branch
end
opts.on('-s', '--sha abcd', 'SHA to cherry pick') do |sha|
options[:sha] = sha
end
opts.on('-r', '--remote abcd', 'Git remote name of dev.gitlab.org (optional, defaults to `dev`)') do |remote|
options[:remote] = remote
end
opts.on('-d', '--dry-run', 'Only show Git commands, without calling them') do |remote|
options[:try] = true
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit class SecurityFix
end def initialize
end @options = self.class.options
parser.parse!
options[:branch] ||= `git rev-parse --abbrev-ref HEAD`
options[:remote] ||= DEFAULT_REMOTE
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/
class SecurityFix
def initialize(options)
@options = options
end end
def ee? def ee?
...@@ -70,7 +33,7 @@ class SecurityFix ...@@ -70,7 +33,7 @@ class SecurityFix
def source_branch def source_branch
branch = "#{original_branch}-#{@options[:version]}" branch = "#{original_branch}-#{@options[:version]}"
branch.prepend("#{BRANCH_PREFIX}-") unless branch.start_with?("#{BRANCH_PREFIX}-") branch.prepend("#{BRANCH_PREFIX}-") unless branch.start_with?("#{BRANCH_PREFIX}-")
branch = branch.freeze branch.freeze
end end
def security_branch def security_branch
...@@ -129,6 +92,48 @@ class SecurityFix ...@@ -129,6 +92,48 @@ class SecurityFix
stderr.close stderr.close
end end
end end
def self.options
{ version: nil, branch: nil, sha: nil }.tap do |options|
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 (optional, defaults to current)') do |branch|
options[:branch] = branch
end
opts.on('-s', '--sha abcd', 'SHA to cherry pick') do |sha|
options[:sha] = sha
end
opts.on('-r', '--remote abcd', 'Git remote name of dev.gitlab.org (optional, defaults to `dev`)') do |remote|
options[:remote] = remote
end
opts.on('-d', '--dry-run', 'Only show Git commands, without calling them') do |remote|
options[:try] = true
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit
end
end
parser.parse!
options[:branch] ||= `git rev-parse --abbrev-ref HEAD`
options[:remote] ||= DEFAULT_REMOTE
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/
end
end
end
end end
SecurityFix.new(options).create! Secpick::SecurityFix.new.create!
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