Skip to content

Commit 4f73b17

Browse files
author
GitLab Bot
committed
Add latest changes from gitlab-org/gitlab@master
1 parent 6742cc8 commit 4f73b17

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

bin/secpick

+56-9
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ module Secpick
3636
end
3737

3838
def git_commands
39-
["git fetch #{@options[:remote]} #{stable_branch}",
40-
"git checkout -B #{source_branch} #{@options[:remote]}/#{stable_branch} --no-track",
41-
"git cherry-pick #{@options[:sha]}",
42-
"git push #{@options[:remote]} #{source_branch} --no-verify",
43-
"git checkout #{@options[:branch]}"]
39+
[
40+
fetch_stable_branch,
41+
create_backport_branch,
42+
cherry_pick_commit,
43+
push_to_remote,
44+
checkout_original_branch
45+
]
4446
end
4547

4648
def gitlab_params
@@ -62,8 +64,10 @@ module Secpick
6264
puts "\nGit commands:".blue
6365
puts git_commands.join("\n")
6466

65-
puts "\nMerge request URL:".blue
66-
puts new_mr_url
67+
if !@options[:merge_request]
68+
puts "\nMerge request URL:".blue
69+
puts new_mr_url
70+
end
6771

6872
puts "\nMerge request params:".blue
6973
pp gitlab_params
@@ -74,7 +78,7 @@ module Secpick
7478
puts stdout.read&.green
7579
puts stderr.read&.red
7680

77-
if wait_thr.value.success?
81+
if wait_thr.value.success? && !@options[:merge_request]
7882
puts "#{new_mr_url}?#{gitlab_params.to_query}".blue
7983
end
8084

@@ -85,7 +89,7 @@ module Secpick
8589
end
8690

8791
def self.options
88-
{ version: nil, branch: nil, sha: nil }.tap do |options|
92+
{ version: nil, branch: nil, sha: nil, merge_request: false }.tap do |options|
8993
parser = OptionParser.new do |opts|
9094
opts.banner = "Usage: #{$0} [options]"
9195
opts.on('-v', '--version 10.0', 'Version') do |version|
@@ -104,6 +108,10 @@ module Secpick
104108
options[:remote] = remote
105109
end
106110

111+
opts.on('--mr', '--merge-request', 'Create relevant security Merge Request targeting the stable branch') do
112+
options[:merge_request] = true
113+
end
114+
107115
opts.on('-d', '--dry-run', 'Only show Git commands, without calling them') do
108116
options[:try] = true
109117
end
@@ -129,6 +137,45 @@ module Secpick
129137
abort("Wrong version format #{options[:version].bold}".red) unless options[:version] =~ /\A\d*\-\d*\Z/
130138
end
131139
end
140+
141+
private
142+
143+
def checkout_original_branch
144+
"git checkout #{@options[:branch]}"
145+
end
146+
147+
def push_to_remote
148+
[
149+
"git push #{@options[:remote]} #{source_branch} --no-verify",
150+
*merge_request_push_options
151+
].join(' ')
152+
end
153+
154+
def merge_request_push_options
155+
return [] unless @options[:merge_request]
156+
157+
[
158+
"-o mr.create",
159+
"-o mr.target='#{stable_branch}'",
160+
"-o mr.description='Please apply Security Release template. /milestone %#{milestone}'"
161+
]
162+
end
163+
164+
def cherry_pick_commit
165+
"git cherry-pick #{@options[:sha]}"
166+
end
167+
168+
def create_backport_branch
169+
"git checkout -B #{source_branch} #{@options[:remote]}/#{stable_branch} --no-track"
170+
end
171+
172+
def fetch_stable_branch
173+
"git fetch #{@options[:remote]} #{stable_branch}"
174+
end
175+
176+
def milestone
177+
@options[:version].gsub('-', '.')
178+
end
132179
end
133180
end
134181

0 commit comments

Comments
 (0)