gitsflow 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ class GitLab::MergeRequest
2
+ @options = {}
3
+ attr_accessor :source_branch, :target_branch, :title, :options, :assignee_id, :labels, :issue_iid, :obj_gitlab, :type, :description
4
+ @labels = []
5
+ def initialize(params = {})
6
+ @source_branch = params[:source_branch]
7
+ @target_branch = params[:target_branch]
8
+ @title = params[:title]
9
+ @labels = params[:labels]
10
+ @issue_iid = params[:issue_iid]
11
+ @type = params[:type]
12
+ @description = params[:description]
13
+ @options = params[:options]
14
+ end
15
+
16
+ def create
17
+ print "Create Merge Request: ".yellow
18
+ print "#{@source_branch} into #{@target_branch}\n\n".green
19
+ assignee_id = GitLab::User.me["id"]
20
+ if type != 'hotfix'
21
+ users = GitLab::User.all
22
+ print "Users list:\n\n".yellow
23
+ print "----------------------------\n".blue
24
+ print "#{"0".ljust(10)} - Empty\n".blue
25
+ users.each do |user|
26
+ print "#{user['id'].to_s.ljust(10)} - #{user['name']}\n".blue
27
+ end
28
+ print "----------------------------\n".blue
29
+ print "Choice user ID for assignee:\n".yellow
30
+ assignee_id = STDIN.gets.chomp
31
+ print "\n#{assignee_id}, "
32
+ print "ok!\n".green
33
+ end
34
+
35
+ url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests"
36
+
37
+ labels = ['merge_request']
38
+ labels << type if type
39
+ @obj_gitlab = GitLab.request_post(url, {
40
+ source_branch: @source_branch,
41
+ target_branch: @target_branch,
42
+ title: @title,
43
+ labels: labels.join(','),
44
+ description: @description,
45
+ assignee_id: assignee_id.to_i
46
+ })
47
+
48
+ print "Merge request created with success!\n\n".green
49
+ end
50
+
51
+
52
+ def create_code_review
53
+ print "Create merge request for code review: ".yellow
54
+ print "#{@source_branch} into #{@target_branch}\n\n".green
55
+ users = GitLab::User.all
56
+ print "Users list:\n\n".yellow
57
+ print "----------------------------\n".blue
58
+ print "#{"0".ljust(10)} - Empty\n".blue
59
+ users.each do |user|
60
+ print "#{user['id'].to_s.ljust(10)} - #{user['name']}\n".blue
61
+ end
62
+ print "----------------------------\n".blue
63
+ print "Choice user ID for assignee code review:\n".yellow
64
+ assignee_id = STDIN.gets.chomp
65
+ print "\n#{assignee_id}, "
66
+ print "ok!\n".green
67
+
68
+ url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests"
69
+ title = "WIP: ##{@issue_iid} - Code review #{@source_branch}"
70
+ @obj_gitlab = GitLab.request_post(url, {
71
+ source_branch: @source_branch,
72
+ target_branch: @target_branch,
73
+ title: title,
74
+ labels: @labels,
75
+ assignee_id: assignee_id.to_i
76
+ })
77
+
78
+ print "Merge request for Code Review created with success!\n\n".green
79
+ end
80
+
81
+
82
+ end
@@ -0,0 +1,20 @@
1
+ class GitLab::User
2
+ attr_accessor :id, :email, :name
3
+
4
+ def initialize(params = {})
5
+ @name = params[:name]
6
+ end
7
+
8
+ def self.me
9
+ GitLab.request_get("projects/#{$GITLAB_PROJECT_ID}/users?search=#{$GITLAB_EMAIL}")[0]
10
+ end
11
+
12
+ def self.all
13
+ GitLab.request_get("projects/#{$GITLAB_PROJECT_ID}/users")
14
+ end
15
+
16
+ def to_s
17
+ end
18
+
19
+
20
+ end
data/lib/config.rb ADDED
@@ -0,0 +1,16 @@
1
+
2
+ begin
3
+ require 'dotenv'
4
+ Dotenv.load(File.join( Dir.pwd, ".env"))
5
+ rescue LoadError
6
+ # Gem loads as it should
7
+ end
8
+ $GITLAB_PROJECT_ID = ENV['GITLAB_PROJECT_ID']
9
+ $GITLAB_TOKEN = ENV['GITLAB_TOKEN']
10
+ $GITLAB_URL_API = ENV['GITLAB_URL_API']
11
+ $GITLAB_EMAIL = ENV['GITLAB_EMAIL'] == "" ? Open3.popen3("git config --local user.email") { |i, o| o.read }.chomp : ENV['GITLAB_EMAIL']
12
+ $GITLAB_LISTS = ENV['GITLAB_LISTS'].split(',') rescue nil
13
+ $GITLAB_NEXT_RELEASE_LIST = ENV['GITLAB_NEXT_RELEASE_LIST']
14
+ $GIT_BRANCH_MASTER= ENV["GIT_BRANCH_MASTER"]
15
+ $GIT_BRANCH_DEVELOP= ENV["GIT_BRANCH_DEVELOP"]
16
+ $GIT_BRANCHES_STAGING= ENV["GIT_BRANCHES_STAGING"].split(',') rescue nil
data/lib/sflow.rb ADDED
@@ -0,0 +1,569 @@
1
+ #!/usr/bin/ruby
2
+ begin
3
+ require 'pry'
4
+ rescue LoadError
5
+ # Gem loads as it should
6
+ end
7
+
8
+ require 'net/http'
9
+
10
+ require "open3"
11
+ require 'uri'
12
+ load 'config.rb'
13
+ load 'string.rb'
14
+ load 'GitLab/gitlab.rb'
15
+ load 'Git/git.rb'
16
+
17
+ # require './lib/gitlab/issue.rb'
18
+ # require './lib/gitlab/merge_request.rb'
19
+ class SFlow
20
+ VERSION = "0.4.3"
21
+ $TYPE = ARGV[0]
22
+ $ACTION = ARGV[1]
23
+
24
+ $PARAM1 = ARGV[2]
25
+ $PARAM2 = ARGV[3..-1]&.join(' ')
26
+
27
+ def self.call
28
+ begin
29
+ print "Loading...\n".yellow
30
+ validates if !['config_', 'help_'].include? ("#{$TYPE}_#{$ACTION}")
31
+ #
32
+ send("#{$TYPE}_#{$ACTION}")
33
+ rescue => e
34
+ set_error e
35
+
36
+ end
37
+ end
38
+ def self.feature_start
39
+ title = $PARAM2 == "" ? $PARAM1 : $PARAM2
40
+ issue = GitLab::Issue.new(title: title, labels: ['feature'])
41
+ issue.create
42
+ branch = "#{issue.iid}-feature/#{$PARAM1}"
43
+ self.start(branch, issue)
44
+ end
45
+
46
+
47
+ def self.bugfix_start
48
+ title = $PARAM2 == "" ? $PARAM1 : $PARAM2
49
+ issue = GitLab::Issue.new(title: title, labels: ['bugfix'])
50
+ issue.create
51
+ branch = "#{issue.iid}-bugfix/#{$PARAM1}"
52
+ self.start(branch, issue)
53
+ end
54
+
55
+ def self.hotfix_start
56
+ title = $PARAM2 == "" ? $PARAM1 : $PARAM2
57
+ issue = GitLab::Issue.new(title: title, labels: ['hotfix', 'production'])
58
+ issue.create
59
+ branch = "#{issue.iid}-hotfix/#{$PARAM1}"
60
+ self.start(branch, issue, $GIT_BRANCH_MASTER)
61
+ end
62
+
63
+ def self.feature_finish
64
+ self.feature_reintegration
65
+ end
66
+
67
+ def self.feature_reintegration
68
+ if (!$PARAM1.match(/\-feature\//))
69
+ raise "This branch is not a feature"
70
+ end
71
+ self.reintegration 'feature'
72
+ end
73
+
74
+ def self.bugfix_reintegration
75
+ if (!$PARAM1.match(/\-bugfix\//))
76
+ raise "This branch is not a bugfix"
77
+ end
78
+ self.reintegration 'bugfix'
79
+ end
80
+
81
+ def self.bugfix_finish
82
+ self.bugfix_reintegration
83
+ end
84
+
85
+ def self.hotfix_reintegration
86
+ if (!$PARAM1.match(/\-hotfix\//))
87
+ raise "This branch is not a hotfix"
88
+ end
89
+ self.reintegration 'hotfix'
90
+ end
91
+
92
+ def self.hotfix_finish
93
+ self.hotfix_reintegration
94
+ end
95
+
96
+ def self.feature_codereview
97
+ if (!$PARAM1.match(/\-feature\//))
98
+ raise "This branch is not a feature"
99
+ end
100
+ self.codereview()
101
+ end
102
+
103
+ def self.bugfix_codereview
104
+ if (!$PARAM1.match(/\-bugfix\//))
105
+ raise "This branch is not a bugfix"
106
+ end
107
+ self.codereview()
108
+ end
109
+
110
+ def self.bugfix_staging
111
+ self.feature_staging
112
+ end
113
+
114
+ def self.feature_staging
115
+ branch = $PARAM1
116
+ issue = GitLab::Issue.find_by_branch(branch)
117
+
118
+ print "Staging branches list:\n\n".yellow
119
+ print "----------------------------\n".blue
120
+ $GIT_BRANCHES_STAGING.each_with_index do |staging, index|
121
+ print "#{index} - #{staging}\n".blue
122
+ end
123
+ print "----------------------------\n".blue
124
+ print "Choice number of target branch:\n".yellow
125
+ target_branch_id = STDIN.gets.chomp
126
+ print "\n#{target_branch_id}, "
127
+ target_branch = $GIT_BRANCHES_STAGING[target_branch_id.to_i]
128
+ if !$GIT_BRANCHES_STAGING.include?(target_branch)
129
+ raise "option invalid!"
130
+ end
131
+ print "ok!\n".green
132
+
133
+
134
+ print "\nAttention: \n".yellow.bg_red
135
+ print "Do you want clean first the target branch or only merge?\n\n".yellow
136
+ print "----------------------------\n".blue
137
+ print "0 - Clean it first, then do merge #{branch} into #{target_branch}\n".blue
138
+ print "1 - Only Merge: Merge #{branch} into #{target_branch}\n".blue
139
+ print "----------------------------\n".blue
140
+ print "Choice number of target branch:\n".yellow
141
+ option_merge = STDIN.gets.chomp
142
+ print "\n#{option_merge}, "
143
+ print "ok!\n".green
144
+
145
+ if option_merge == "0"
146
+ Git.reset_hard branch, target_branch
147
+ elsif option_merge == "1"
148
+ Git.merge branch, target_branch
149
+ else
150
+ raise "Wrong choice"
151
+ end
152
+ new_labels = [target_branch, 'Staging']
153
+ remove_labels = $GITLAB_LISTS
154
+ old_labels = issue.obj_gitlab["labels"]
155
+ old_labels.delete_if{|label| remove_labels.include? label}
156
+ issue.labels = (old_labels + new_labels).uniq
157
+ issue.update
158
+
159
+ self.codereview
160
+ end
161
+
162
+ def self.release_start
163
+ version = $PARAM1
164
+ if !version
165
+ raise "param 'VERSION' not found"
166
+ end
167
+ issues = GitLab::Issue.from_list($GITLAB_NEXT_RELEASE_LIST).select{|i| !i.labels.include? 'ready_to_deploy'}
168
+ issues_total = issues.size
169
+
170
+ if issues_total == 0
171
+ raise "Not exist issues ready for start release version"
172
+ end
173
+
174
+ issues_urgent = issues.select{|i| i.labels.include? 'urgent'}
175
+ issues_urgent_total = issues_urgent.size
176
+ issue_title = "Release version #{version}\n"
177
+
178
+ issue_release = GitLab::Issue.find_by(title: issue_title) rescue nil
179
+
180
+ if issue_release
181
+ print "This issue already exists, do you want to continue using it? (y/n):".yellow.bg_red
182
+
183
+ print"\n If you choose 'n', a new issue will be created!\n"
184
+ print "\n"
185
+ option = STDIN.gets.chomp
186
+ else
187
+ option = 'n'
188
+ end
189
+
190
+ if option == 'n'
191
+ issue_release = GitLab::Issue.new(title: issue_title)
192
+ issue_release.create
193
+ end
194
+
195
+ new_labels = []
196
+ changelogs = []
197
+
198
+ release_branch = "#{issue_release.iid}-release/#{version}"
199
+ print "Creating release version #{version}\n"
200
+
201
+ begin
202
+
203
+ Git.delete_branch(release_branch)
204
+ Git.checkout 'develop'
205
+ Git.new_branch release_branch
206
+
207
+ print "Issue(s) title(s): \n".yellow
208
+ issues.each do |issue|
209
+ print " -> #{issue.title}\n"
210
+ end
211
+ print "\n"
212
+
213
+ # if issues_urgent_total > 0
214
+ print "Attention!".yellow.bg_red
215
+ print "\n\nChoose an option for merge:\n".yellow
216
+ print "----------------------------\n".blue
217
+ print "#{"0".ljust(10)} - Only #{issues_urgent_total} hotfix/urgent issues\n".blue if issues_urgent_total > 0
218
+ print "#{"1".ljust(10)} - All #{issues_total} issues\n".blue
219
+ print "----------------------------\n".blue
220
+ print "Choice a number:\n".yellow
221
+ option = STDIN.gets.chomp
222
+ # else
223
+ # option = "1"
224
+ # end
225
+
226
+ case option
227
+ when "0"
228
+ print "Issue(s) title(s): \n"
229
+ issues_urgent.each do |issue|
230
+ print " -> #{issue.title}\n"
231
+ end
232
+
233
+ issues_urgent.each do |issue|
234
+
235
+ Git.merge(issue.branch, release_branch)
236
+ changelogs << "* ~changelog #{issue.msg_changelog} \n"
237
+ new_labels << 'hotfix'
238
+
239
+ end
240
+ issues = issues_urgent
241
+ when "1"
242
+ type = 'other'
243
+ print "Next release has total (#{issues_total}) issues.\n\n".yellow
244
+ print "Issue(s) title(s): \n".yellow
245
+ issues.each do |issue|
246
+ print " -> #{issue.title}\n"
247
+ end
248
+ issues.each do |issue|
249
+ Git.merge(issue.branch, release_branch)
250
+ changelogs << "* ~changelog #{issue.msg_changelog} \n"
251
+
252
+ end
253
+ else
254
+ raise "option invalid!"
255
+ end
256
+ print "Changelog messages:\n\n".yellow
257
+ version_header = "Release version #{version}\n"
258
+ print version_header.blue
259
+ msgs_changelog = []
260
+ changelogs.each do |clog|
261
+ msg_changelog = "#{clog.strip.chomp.gsub('* ~changelog ', ' - ')}\n"
262
+ msgs_changelog << msg_changelog
263
+ print msg_changelog.light_blue
264
+ end
265
+ print "\nSetting changelog message in CHANGELOG\n".yellow
266
+ sleep 2
267
+
268
+ system('touch CHANGELOG')
269
+ file_changelog = IO.read 'CHANGELOG'
270
+ IO.write 'CHANGELOG', version_header + msgs_changelog.join('') + file_changelog
271
+
272
+ system('git add CHANGELOG')
273
+ system("git commit -m 'update CHANGELOG version #{version}'")
274
+ Git.push release_branch
275
+
276
+ issue_release.description = "#{changelogs.join("")}\n * #{issues.map{|i| "##{i.iid},"}.join(' ')}"
277
+
278
+ issue_release.labels = ['ready_to_deploy', 'Next Release']
279
+ issue_release.set_default_branch(release_branch)
280
+ issue_release.update
281
+ issues.each do |issue|
282
+ issue.labels = (issue.labels + new_labels).uniq
283
+ issue.close
284
+ end
285
+ print "\nYou are on branch: #{release_branch}\n".yellow
286
+ print "\nRelease #{version} created with success!\n\n".yellow
287
+
288
+
289
+ rescue => exception
290
+ Git.delete_branch(release_branch)
291
+
292
+ raise exception.message
293
+ end
294
+
295
+ end
296
+
297
+ def self.release_finish
298
+ version = $PARAM1
299
+ if !version
300
+ raise "param 'VERSION' not found"
301
+ end
302
+ new_labels = []
303
+
304
+ release_branch = "-release/#{version}"
305
+ issue_release = GitLab::Issue.find_by_branch(release_branch)
306
+
307
+ Git.merge issue_release.branch, 'develop'
308
+ Git.push 'develop'
309
+
310
+
311
+ type = issue_release.labels.include?('hotfix') ? 'hotfix' : nil
312
+ mr_master = GitLab::MergeRequest.new(
313
+ source_branch: issue_release.branch,
314
+ target_branch: $GIT_BRANCH_MASTER,
315
+ issue_iid: issue_release.iid,
316
+ title: "Reintegration release #{version}: #{issue_release.branch} into master",
317
+ description: "Closes ##{issue_release.iid}",
318
+ type: type
319
+ )
320
+ mr_master.create
321
+
322
+ # end
323
+ # mr_develop = GitLab::MergeRequest.new(
324
+ # source_branch: issue_release.branch,
325
+ # target_branch: 'develop',
326
+ # issue_iid: issue_release.iid,
327
+ # title: "##{issue_release.iid} - #{version} - Reintegration #{issue_release.branch} into develop",
328
+ # type: 'hotfix'
329
+ # )
330
+ # mr_develop.create
331
+
332
+
333
+
334
+ # remove_labels = [$GITLAB_NEXT_RELEASE_LIST]
335
+ remove_labels = []
336
+ old_labels = issue_release.obj_gitlab["labels"] + ['merge_request']
337
+ old_labels.delete_if{|label| remove_labels.include? label}
338
+ issue_release.labels = (old_labels + new_labels).uniq
339
+ issue_release.update
340
+ print "\nRelease #{version} finished with success!\n\n".yellow
341
+
342
+
343
+ end
344
+
345
+
346
+ def self.uninstall_
347
+ puts "\n\Uninstall git alias\n\n".yellow
348
+ print " \u{1F611} git sflow alias"
349
+ print " (removing...) \r".yellow
350
+ sleep 2
351
+ system('git config --local --unset alias.sflow')
352
+ print " \u{1F601}\ git sflow alias"
353
+ print " (removed) \u{2714} ".green
354
+ print "\n\n"
355
+ print "Bye Bye"
356
+ print "\n\n"
357
+
358
+ end
359
+
360
+ def self.install_
361
+ puts "\n\nInstalling git alias\n\n".yellow
362
+ print " \u{1F611} git sflow alias"
363
+ print " (instaling...) \r".yellow
364
+ GitLab.create_labels
365
+ sleep 2
366
+ system("git config --local alias.sflow '!sh -c \" sflow $1 $2 $3 $4\" - '")
367
+ print " \u{1F601}\ git sflow alias"
368
+ print " (instaled) \u{2714} ".green
369
+ print "\n\n"
370
+ print "git sflow help\n\n"
371
+ print "git sflow config\n\n"
372
+ print "GitSFlow installed with success!\n\n".green
373
+ # self.help_
374
+ # self.config_
375
+
376
+ end
377
+
378
+
379
+ def self.push_origin
380
+ branch = $PARAM1
381
+ log_messages = Git.log_last_changes branch
382
+ issue = GitLab::Issue.find_by_branch branch
383
+ Git.push branch
384
+ if (log_messages != "")
385
+ print "Send messages commit for issue\n".yellow
386
+ issue.add_comment(log_messages)
387
+ end
388
+
389
+ remove_labels = $GIT_BRANCHES_STAGING + ['Staging', $GITLAB_NEXT_RELEASE_LIST]
390
+ old_labels = issue.obj_gitlab["labels"]
391
+ old_labels.delete_if{|label| remove_labels.include? label}
392
+
393
+ issue.labels = old_labels + ['Doing']
394
+ issue.update
395
+ print "Success!\n\n".yellow
396
+ end
397
+
398
+ private
399
+
400
+ def self.config_
401
+ print "\n\---------- Configuration ---------- \n".light_blue
402
+ print "\nsflow config \nor\ngit sflow config \n\n".light_blue
403
+
404
+ print "\In your project create or update file .env with variables below:\n\n"
405
+ print "GITLAB_PROJECT_ID=\n".pink
406
+ print "GITLAB_TOKEN=\n".pink
407
+ print "GITLAB_URL_API=\n".pink
408
+ print "GITLAB_EMAIL=\n".pink
409
+ print "GITLAB_LISTS=To Do,Doing,Next Release,Staging\n".pink
410
+ print "GITLAB_NEXT_RELEASE_LIST=Next Release\n".pink
411
+ print "GIT_BRANCH_MASTER=master\n".pink
412
+ print "GIT_BRANCH_DEVELOP=develop\n".pink
413
+ print "GIT_BRANCHES_STAGING=staging_1,staging_2\n".pink
414
+
415
+ end
416
+
417
+ def self.set_error(e)
418
+ print "\n\n"
419
+ print "Error!".yellow.bg_red
420
+ print "\n"
421
+ print "#{e.message}".yellow.bg_red
422
+ print "\n\n"
423
+ print "#{e.backtrace}".yellow.bg_red
424
+ print "\n\n"
425
+ end
426
+
427
+ def self.validates
428
+ print "Running validations... \n\n".yellow
429
+ if !$GITLAB_PROJECT_ID || !$GITLAB_TOKEN || !$GITLAB_URL_API ||
430
+ !$GIT_BRANCH_MASTER || !$GIT_BRANCH_DEVELOP || !$GITLAB_LISTS || !$GITLAB_NEXT_RELEASE_LIST
431
+ print "Variables not configured\n".yellow
432
+ raise "Run `sflow config` for help"
433
+ end
434
+
435
+ if !$TYPE && !$ACTION
436
+ print "Command invalid!\n".yellow
437
+ raise "Run `sflow help` for help"
438
+ end
439
+ branchs_validations = $GIT_BRANCHES_STAGING + [$GIT_BRANCH_MASTER, $GIT_BRANCH_DEVELOP]
440
+ Git.exist_branch?(branchs_validations.join(' ')) rescue raise "You need to create branches #{branchs_validations.join(', ')}"
441
+
442
+ end
443
+
444
+ def self.help_
445
+ print "\n\n---------- Help ---------- \n".light_blue
446
+ print "\nsflow help\nor\ngit sflow help\n\n".light_blue
447
+ print "1 - git sflow feature start FEATURE DESCRIPTION \n".yellow
448
+ print "2 - git sflow feature [reintegration|finish] FEATURE_BRANCH\n".yellow
449
+ print "3 - git sflow feature codereview BRANCH\n".yellow
450
+ print "4 - git sflow feature staging SOURCE_BRANCH\n".yellow
451
+ print "5 - git sflow bugfix start BUGFIX DESCRIPTION\n".yellow
452
+ print "6 - git sflow bugfix [reintegration|finish] BUGFIX_BRANCH\n".yellow
453
+ print "7 - git sflow bugfix codereview BUGFIX_BRANCH\n".yellow
454
+ print "8 - git sflow bugfix staging BUGFIX_BRANCH\n".yellow
455
+ print "9 - git sflow hotfix start HOTFIX DESCRIPTION\n".yellow
456
+ print "10 - git sflow hotfix [reintegration|finish] HOTFIX_BRANCH\n".yellow
457
+ print "11 - git sflow release start RELEASE\n".yellow
458
+ print "12 - git sflow release finish RELEASE\n".yellow
459
+ print "13 - git sflow push origin BRANCH\n".yellow
460
+
461
+ choice = -1
462
+ question = "Choice a number for show a example or 0 for exit:\n\n".light_blue
463
+ print question
464
+ choice = STDIN.gets.chomp
465
+ print ""
466
+ case choice
467
+ when '1'
468
+ print "-> git sflow feature start Ticket#9999 'Ticket#9999 - Create new...'\n\n"
469
+ when '2'
470
+ print "-> git sflow feature reintegration 11-feature/Ticket#9999\n\n"
471
+ when '3'
472
+ print "-> git sflow feature codereview 11-feature/Ticket#9999\n\n"
473
+ when '4'
474
+ print "-> git sflow feature staging 11-feature/Ticket#9999\n\n"
475
+ when '5'
476
+ print "-> git sflow bugfix start Ticket#9999 'Ticket#9999 Bug ...'\n\n"
477
+ when '6'
478
+ print "-> git sflow bugfix finish 12-bugfix/Ticket#9999'\n\n"
479
+ when '7'
480
+ print "-> git sflow bugfix codereview 12-bugfix/Ticket#9999\n"
481
+ when '8'
482
+ print "-> git sflow bugfix staging 12-bugfix/Ticket#9999\n"
483
+ when '9'
484
+ print "-> git sflow hotfix start Ticket#9999 'Ticket#9999 Bug at production in...'\n\n"
485
+ when '10'
486
+ print "-> git sflow hotfix reintegration Ticket#9999'\n\n"
487
+ when '11'
488
+ print "-> git sflow release start v5.5.99'\n\n"
489
+ when '12'
490
+ print "-> git sflow release finish v5.5.99'\n\n"
491
+ when '13'
492
+ print "-> git sflow push BRANCH\n\n"
493
+ when '0'
494
+ else
495
+ end
496
+ print "See you soon!".green
497
+ print "\n\n"
498
+
499
+
500
+ end
501
+
502
+ def self.reintegration type = "feature"
503
+ # Git.fetch ref_branch
504
+ # Git.checkout ref_branch
505
+ # Git.pull ref_branch
506
+ source_branch = $PARAM1
507
+ issue = GitLab::Issue.find_by_branch(source_branch)
508
+ print "Title: #{issue.title}\n\n"
509
+ print "Changelog message:\n--> ".yellow
510
+ message_changelog = STDIN.gets.chomp
511
+ print "\n ok!\n\n".green
512
+ new_labels = []
513
+ if (type == 'hotfix')
514
+ !source_branch.match('hotfix') rescue raise "invalid branch!"
515
+ new_labels << 'hotfix'
516
+ new_labels << 'urgent'
517
+ else
518
+ (!source_branch.match('feature') && !source_branch.match('bugfix')) rescue raise "invalid branch!"
519
+ end
520
+ remove_labels = $GIT_BRANCHES_STAGING + $GITLAB_LISTS + ['Staging']
521
+ new_labels << 'changelog'
522
+ new_labels << $GITLAB_NEXT_RELEASE_LIST
523
+ old_labels = issue.obj_gitlab["labels"]
524
+ old_labels.delete_if{|label| remove_labels.include? label}
525
+ issue.labels = (old_labels + new_labels).uniq
526
+ issue.description.gsub!(/\* \~changelog .*\n?/,'')
527
+ issue.description = "#{issue.description} \n* ~changelog #{message_changelog}"
528
+ print "Setting changelog: ".yellow
529
+ print "#{message_changelog}\n".green
530
+ print "Moving issue to list: ".yellow
531
+ print "#{$GITLAB_NEXT_RELEASE_LIST}\n".green
532
+ issue.update
533
+
534
+ end
535
+
536
+ def self.start branch, issue, ref_branch = "develop"
537
+ Git.fetch ref_branch
538
+ Git.checkout ref_branch
539
+ Git.pull ref_branch
540
+
541
+ description = "* ~default_branch #{branch}"
542
+
543
+ issue.description = description
544
+ issue.update
545
+
546
+ Git.new_branch branch
547
+ Git.push branch
548
+
549
+ print "\nYou are on branch: #{branch}\n\n".yellow
550
+ end
551
+
552
+ def self.codereview
553
+ Git.fetch "develop"
554
+ Git.checkout "develop"
555
+ Git.pull "develop"
556
+ source_branch = $PARAM1
557
+ issue = GitLab::Issue.find_by_branch(source_branch)
558
+ # issue.move
559
+ mr = GitLab::MergeRequest.new(
560
+ source_branch: source_branch,
561
+ target_branch: 'develop',
562
+ issue_iid: issue.iid
563
+ )
564
+ mr.create_code_review
565
+ issue.labels = (issue.obj_gitlab["labels"] + ['code_review']).uniq
566
+ issue.update
567
+ end
568
+ end
569
+