gitsflow 0.6.3 → 0.8.2.alfa
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.
- checksums.yaml +4 -4
- data/.env.yml +1 -0
- data/Gemfile.lock +66 -3
- data/README.md +5 -28
- data/bin/sflow +2 -2
- data/gitsflow.gemspec +62 -34
- data/lib/Git/git.rb +42 -42
- data/lib/GitLab/gitlab.rb +79 -46
- data/lib/GitLab/issue.rb +84 -52
- data/lib/GitLab/merge_request.rb +76 -57
- data/lib/GitLab/user.rb +3 -3
- data/lib/Utils/changelog.rb +10 -0
- data/lib/Utils/putdotenv.rb +3 -0
- data/lib/command.rb +19 -0
- data/lib/config.rb +30 -12
- data/lib/menu.rb +253 -0
- data/lib/sflow/sflow.rb +666 -0
- data/lib/sflow/version.rb +3 -0
- data/lib/tty_integration.rb +50 -0
- metadata +298 -11
- data/lib/sflow.rb +0 -651
data/lib/sflow/sflow.rb
ADDED
@@ -0,0 +1,666 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
begin
|
3
|
+
require 'pry'
|
4
|
+
rescue LoadError
|
5
|
+
# Gem loads as it should
|
6
|
+
end
|
7
|
+
# require 'i18n'
|
8
|
+
|
9
|
+
require 'net/http'
|
10
|
+
require 'pastel'
|
11
|
+
require 'open3'
|
12
|
+
require 'date'
|
13
|
+
require 'uri'
|
14
|
+
require 'config'
|
15
|
+
|
16
|
+
require 'tty_integration'
|
17
|
+
require 'string'
|
18
|
+
require 'GitLab/gitlab'
|
19
|
+
require 'Git/git'
|
20
|
+
require 'Utils/changelog'
|
21
|
+
require 'sflow/version'
|
22
|
+
require 'menu'
|
23
|
+
|
24
|
+
# require 'utils/putdotenv.rb'
|
25
|
+
|
26
|
+
# require './lib/gitlab/issue.rb'
|
27
|
+
# require './lib/gitlab/merge_request.rb'
|
28
|
+
module SFlow
|
29
|
+
class SFlow
|
30
|
+
extend TtyIntegration
|
31
|
+
|
32
|
+
# $TYPE = ARGV[0]&.encode("UTF-8")
|
33
|
+
# $ACTION = ARGV[1]&.encode("UTF-8")
|
34
|
+
|
35
|
+
# branch_name = ARGV[2]&.encode("UTF-8")
|
36
|
+
# $PARAM2 = ARGV[3..-1]&.join(' ')&.encode("UTF-8")
|
37
|
+
|
38
|
+
def self.call
|
39
|
+
system('clear')
|
40
|
+
Config.init
|
41
|
+
# prompt.ok("GitSflow #{VERSION}")
|
42
|
+
box = TTY::Box.frame align: :center, width: TTY::Screen.width, height: 4,
|
43
|
+
title: { bottom_right: pastel.cyan("(v#{VERSION})") } do
|
44
|
+
pastel.green('GitSflow')
|
45
|
+
end
|
46
|
+
print box
|
47
|
+
validates
|
48
|
+
Menu.new.principal
|
49
|
+
rescue StandardError => e
|
50
|
+
set_error e
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.feature_start(external_id_ref, branch_description, parent_branch_name = nil)
|
54
|
+
@@bar = bar('Processando ')
|
55
|
+
@@bar.start
|
56
|
+
2.times do
|
57
|
+
sleep(0.2)
|
58
|
+
@@bar.advance
|
59
|
+
end
|
60
|
+
parent_issue_id = parent_branch_name.to_s.match(/^(\d*)-/).to_a.last
|
61
|
+
parent_issue_id_formated = "-##{parent_issue_id}" if parent_branch_name
|
62
|
+
title = ''
|
63
|
+
title += "(##{parent_issue_id}) " if parent_branch_name
|
64
|
+
title += branch_description || external_id_ref
|
65
|
+
|
66
|
+
issue = GitLab::Issue.new(title: title, labels: ['feature'])
|
67
|
+
issue.create
|
68
|
+
branch = "#{issue.iid}-feature/#{external_id_ref}#{parent_issue_id_formated}"
|
69
|
+
start(branch, issue, $GIT_BRANCH_DEVELOP, parent_branch_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.bugfix_start(external_id_ref, branch_description, parent_branch_name = nil)
|
73
|
+
@@bar = bar('Processando ')
|
74
|
+
@@bar.start
|
75
|
+
2.times do
|
76
|
+
sleep(0.2)
|
77
|
+
@@bar.advance
|
78
|
+
end
|
79
|
+
parent_issue_id = parent_branch_name.to_s.match(/^(\d*)-/).to_a.last
|
80
|
+
parent_issue_id_formated = "-##{parent_issue_id}" if parent_branch_name
|
81
|
+
title = ''
|
82
|
+
title += "(##{parent_issue_id}) " if parent_branch_name
|
83
|
+
title += branch_description || external_id_ref
|
84
|
+
issue = GitLab::Issue.new(title: title, labels: ['bugfix'])
|
85
|
+
issue.create
|
86
|
+
branch = "#{issue.iid}-bugfix/#{external_id_ref}#{parent_issue_id_formated}"
|
87
|
+
start(branch, issue, $GIT_BRANCH_DEVELOP, parent_branch_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.hotfix_start(external_id_ref, branch_description, parent_branch_name = nil)
|
91
|
+
@@bar = bar('Processando ')
|
92
|
+
@@bar.start
|
93
|
+
2.times do
|
94
|
+
sleep(0.2)
|
95
|
+
@@bar.advance
|
96
|
+
end
|
97
|
+
parent_issue_id = parent_branch_name.to_s.match(/^(\d*)-/).to_a.last
|
98
|
+
parent_issue_id_formated = "-##{parent_issue_id}" if parent_branch_name
|
99
|
+
title = ''
|
100
|
+
title += "(##{parent_issue_id}) " if parent_branch_name
|
101
|
+
title += branch_description || external_id_ref
|
102
|
+
issue = GitLab::Issue.new(title: title, labels: %w[hotfix production])
|
103
|
+
issue.create
|
104
|
+
branch = "#{issue.iid}-hotfix/#{external_id_ref}#{parent_issue_id_formated}"
|
105
|
+
start(branch, issue, $GIT_BRANCH_MASTER, parent_branch_name)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.feature_finish(branch_name)
|
109
|
+
feature_reintegration branch_name
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.feature_reintegration(branch_name)
|
113
|
+
raise 'A branch informada não é do tipo feature' unless branch_name.match(%r{-feature/})
|
114
|
+
|
115
|
+
@@bar = bar('Processando ')
|
116
|
+
@@bar.start
|
117
|
+
reintegration 'feature', branch_name
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.bugfix_reintegration(branch_name)
|
121
|
+
raise 'A branch informada não é do tipo bugfix' unless branch_name.match(%r{-bugfix/})
|
122
|
+
|
123
|
+
@@bar = bar('Processando ')
|
124
|
+
@@bar.start
|
125
|
+
reintegration 'bugfix', branch_name
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.bugfix_finish(branch_name)
|
129
|
+
bugfix_reintegration branch_name
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.hotfix_reintegration(branch_name)
|
133
|
+
raise 'A branch informada não é do tipo hotfix' unless branch_name.match(%r{-hotfix/})
|
134
|
+
|
135
|
+
@@bar = bar('Processando ')
|
136
|
+
@@bar.start
|
137
|
+
reintegration 'hotfix', branch_name
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.hotfix_finish(branch_name)
|
141
|
+
hotfix_reintegration branch_name
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.feature_codereview(branch_name)
|
145
|
+
raise 'A branch informada não é do tipo feature' unless branch_name.match(%r{-feature/})
|
146
|
+
|
147
|
+
codereview(branch_name)
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.bugfix_codereview(branch_name)
|
151
|
+
raise 'A branch informada não é do tipo bugfix' unless branch_name.match(%r{-bugfix/})
|
152
|
+
|
153
|
+
codereview(branch_name)
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.hotfix_staging(branch_name)
|
157
|
+
raise 'A branch informada não é do tipo hotfix' unless branch_name.match(%r{-hotfix/})
|
158
|
+
|
159
|
+
staging branch_name
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.bugfix_staging(branch_name)
|
163
|
+
raise 'A branch informada não é do tipo bugfix' unless branch_name.match(%r{-bugfix/})
|
164
|
+
|
165
|
+
staging branch_name
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.feature_staging(branch_name)
|
169
|
+
raise 'A branch informada não é do tipo feature' unless branch_name.match(%r{-feature/})
|
170
|
+
|
171
|
+
staging branch_name
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.release_start
|
175
|
+
version = prompt.ask('Por favor dígite o nº da versão:')
|
176
|
+
raise "parâmetro 'VERSION' não encontrado" unless version
|
177
|
+
|
178
|
+
issues = GitLab::Issue.from_list($GITLAB_NEXT_RELEASE_LIST).select { |i| !i.labels.include? 'ready_to_deploy' }
|
179
|
+
issues_total = issues.size
|
180
|
+
|
181
|
+
raise 'Não existem issues disponíveis para inciar uma nova Versão de Release' if issues_total == 0
|
182
|
+
|
183
|
+
issues_urgent = issues.select { |i| i.labels.include? 'urgent' }
|
184
|
+
issues_urgent_total = issues_urgent.size
|
185
|
+
issue_title = "Release version #{version}\n"
|
186
|
+
|
187
|
+
issue_release = begin
|
188
|
+
GitLab::Issue.find_by(title: issue_title)
|
189
|
+
rescue StandardError
|
190
|
+
nil
|
191
|
+
end
|
192
|
+
|
193
|
+
if issue_release
|
194
|
+
option = prompt.yes? 'Já existem uma Issue com mesmo nome criada previamente. Se você quer reutilizar a issue digite Y, caso deseja criar uma nova, digite n? :'.yellow.bg_red
|
195
|
+
else
|
196
|
+
option = 'n'
|
197
|
+
end
|
198
|
+
|
199
|
+
if option == 'n'
|
200
|
+
issue_release = GitLab::Issue.new(title: issue_title)
|
201
|
+
issue_release.create
|
202
|
+
end
|
203
|
+
|
204
|
+
new_labels = []
|
205
|
+
changelogs = []
|
206
|
+
|
207
|
+
release_branch = "#{issue_release.iid}-release/#{version}"
|
208
|
+
# print "Creating release version #{version}\n"
|
209
|
+
|
210
|
+
begin
|
211
|
+
# Git.delete_branch(release_branch)
|
212
|
+
Git.checkout $GIT_BRANCH_DEVELOP
|
213
|
+
Git.new_branch release_branch
|
214
|
+
|
215
|
+
prompt.say "\nIssues disponíveis para criar versão:"
|
216
|
+
header = [pastel.cyan('Issue'), pastel.cyan('Labels')]
|
217
|
+
prompt.say(
|
218
|
+
table.new(header,
|
219
|
+
issues.map do |i|
|
220
|
+
[i.title, i.labels.join(',')]
|
221
|
+
end, orientation: :vertical).render(:unicode)
|
222
|
+
)
|
223
|
+
|
224
|
+
# prompt.say pastel.yellow "Atenção!"
|
225
|
+
|
226
|
+
option = prompt.select("\nEscolha uma opção de Branch:", symbols: { marker: '>' }) do |menu|
|
227
|
+
menu.choice("Somente as (#{issues_urgent_total}) issues de hotfix/urgent", '0') if issues_urgent_total > 0
|
228
|
+
menu.choice "Todas as (#{issues_total}) issues", '1'
|
229
|
+
end
|
230
|
+
|
231
|
+
case option
|
232
|
+
when '0'
|
233
|
+
prompt.say "Título das Issues: \n"
|
234
|
+
|
235
|
+
# header = [pastel.cyan('Issues'), pastel.cyan('Labels')]
|
236
|
+
# prompt.say (
|
237
|
+
# table.new(header,
|
238
|
+
# issues_urgent.map do |i|
|
239
|
+
# [i.title, i.labels.join(',')]
|
240
|
+
# end
|
241
|
+
# ).render(:unicode))
|
242
|
+
|
243
|
+
issues_urgent.each do |issue|
|
244
|
+
Git.merge(issue.branch, release_branch)
|
245
|
+
changelogs << "* ~changelog #{issue.msg_changelog} \n"
|
246
|
+
new_labels << 'hotfix'
|
247
|
+
end
|
248
|
+
issues = issues_urgent
|
249
|
+
when '1'
|
250
|
+
type = 'other'
|
251
|
+
# promtp.say "Existem (#{issues_total}) issues disponíveis para Próxima Release.\n\n".yellow
|
252
|
+
|
253
|
+
# header = [pastel.cyan('Issues'), pastel.cyan('Labels')]
|
254
|
+
# prompt.say (
|
255
|
+
# table.new(header,
|
256
|
+
# issues.map do |i|
|
257
|
+
# [i.title, i.labels.join(',')]
|
258
|
+
# end
|
259
|
+
# ).render(:unicode))
|
260
|
+
issues.each do |issue|
|
261
|
+
Git.merge(issue.branch, release_branch)
|
262
|
+
changelogs << "* ~changelog #{issue.msg_changelog} \n"
|
263
|
+
end
|
264
|
+
else
|
265
|
+
raise 'Opção Inválida!'
|
266
|
+
end
|
267
|
+
prompt.say pastel.bold 'Mensagens incluida no change CHANGELOG:'
|
268
|
+
|
269
|
+
d_split = $SFLOW_TEMPLATE_RELEASE_DATE_FORMAT.split('/')
|
270
|
+
date = Date.today.strftime("%#{d_split[0]}/%#{d_split[1]}/%#{d_split[2]}")
|
271
|
+
version_header = "#{$SFLOW_TEMPLATE_RELEASE.gsub('{version}', version).gsub('{date}', date)}\n"
|
272
|
+
|
273
|
+
# print version_header.blue
|
274
|
+
msgs_changelog = []
|
275
|
+
changelogs.each do |clog|
|
276
|
+
msg_changelog = "#{clog.strip.chomp.gsub('* ~changelog ', ' - ')}\n"
|
277
|
+
msgs_changelog << msg_changelog
|
278
|
+
# print msg_changelog.light_blue
|
279
|
+
end
|
280
|
+
msgs_changelog << "\n"
|
281
|
+
|
282
|
+
header = [pastel.cyan(version_header.delete("\n"))]
|
283
|
+
prompt.say(
|
284
|
+
table.new(header,
|
285
|
+
[
|
286
|
+
msgs_changelog.map do |msg|
|
287
|
+
msg.delete("\n")
|
288
|
+
end
|
289
|
+
]).render(:unicode)
|
290
|
+
)
|
291
|
+
# print "\nConfigurando mensagem de changelog no arquivo CHANGELOG\n".yellow
|
292
|
+
|
293
|
+
system('touch CHANGELOG')
|
294
|
+
|
295
|
+
line = version_header + ' ' + msgs_changelog.join('')
|
296
|
+
File.write('CHANGELOG', line + File.open('CHANGELOG').read.encode('UTF-8'), mode: 'w')
|
297
|
+
|
298
|
+
system('git add CHANGELOG')
|
299
|
+
system(%(git commit -m "update CHANGELOG version #{version}"))
|
300
|
+
Git.push release_branch
|
301
|
+
|
302
|
+
issue_release.description = "#{changelogs.join('')}\n"
|
303
|
+
|
304
|
+
issue_release.labels = ['ready_to_deploy', 'Next Release']
|
305
|
+
issue_release.set_default_branch(release_branch)
|
306
|
+
|
307
|
+
tasks = []
|
308
|
+
issues.each do |issue|
|
309
|
+
tasks << "* ~tasks #{issue.list_tasks} \n" if issue.description.match(/(\* ~tasks .*)+/)
|
310
|
+
end
|
311
|
+
|
312
|
+
if tasks.size > 0
|
313
|
+
prompt.say pastel.bold 'Lista de Tasks:'.yellow
|
314
|
+
new_labels << 'tasks'
|
315
|
+
|
316
|
+
header = [pastel.cyan('Tasks')]
|
317
|
+
prompt.say(
|
318
|
+
table.new(header,
|
319
|
+
[
|
320
|
+
tasks.map do |task|
|
321
|
+
task.strip.chomp.gsub('* ~tasks ', ' - ').delete("\n")
|
322
|
+
end
|
323
|
+
]).render(:unicode)
|
324
|
+
)
|
325
|
+
# tasks.each do |task|
|
326
|
+
# task = "#{task.strip.chomp.gsub('* ~tasks ', ' - ')}\n"
|
327
|
+
# print task.light_blue
|
328
|
+
# end
|
329
|
+
issue_release.description += "#{tasks.join('')}\n"
|
330
|
+
end
|
331
|
+
|
332
|
+
issues.each do |issue|
|
333
|
+
issue.labels = (issue.labels + new_labels).uniq
|
334
|
+
issue.close
|
335
|
+
end
|
336
|
+
|
337
|
+
# print "\Você está na branch: #{release_branch}\n".yellow
|
338
|
+
success "Release #{version} criada com sucesso!"
|
339
|
+
|
340
|
+
issue_release.description += "* #{issues.map { |i| "##{i.iid}," }.join(' ')}"
|
341
|
+
|
342
|
+
issue_release.update
|
343
|
+
rescue StandardError => e
|
344
|
+
Git.delete_branch(release_branch)
|
345
|
+
|
346
|
+
raise e.message
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def self.release_finish(branch_name)
|
351
|
+
version = branch_name
|
352
|
+
|
353
|
+
new_labels = []
|
354
|
+
|
355
|
+
release_branch = "-release/#{version}"
|
356
|
+
issue_release = GitLab::Issue.find_by_branch(release_branch)
|
357
|
+
|
358
|
+
Git.merge issue_release.branch, $GIT_BRANCH_DEVELOP
|
359
|
+
Git.push $GIT_BRANCH_DEVELOP
|
360
|
+
|
361
|
+
type = issue_release.labels.include?('hotfix') ? 'hotfix' : nil
|
362
|
+
mr_master = GitLab::MergeRequest.new(
|
363
|
+
source_branch: issue_release.branch,
|
364
|
+
target_branch: $GIT_BRANCH_MASTER,
|
365
|
+
issue_iid: issue_release.iid,
|
366
|
+
title: "Reintegration release #{version}: #{issue_release.branch} into #{$GIT_BRANCH_MASTER}",
|
367
|
+
description: "Closes ##{issue_release.iid}",
|
368
|
+
type: type
|
369
|
+
)
|
370
|
+
mr_master.create
|
371
|
+
|
372
|
+
# end
|
373
|
+
# mr_develop = GitLab::MergeRequest.new(
|
374
|
+
# source_branch: issue_release.branch,
|
375
|
+
# target_branch: $GIT_BRANCH_DEVELOP,
|
376
|
+
# issue_iid: issue_release.iid,
|
377
|
+
# title: "##{issue_release.iid} - #{version} - Reintegration #{issue_release.branch} into develop",
|
378
|
+
# type: 'hotfix'
|
379
|
+
# )
|
380
|
+
# mr_develop.create
|
381
|
+
|
382
|
+
# remove_labels = [$GITLAB_NEXT_RELEASE_LIST]
|
383
|
+
remove_labels = []
|
384
|
+
old_labels = issue_release.obj_gitlab['labels'] + ['merge_request']
|
385
|
+
old_labels.delete_if { |label| remove_labels.include? label }
|
386
|
+
issue_release.labels = (old_labels + new_labels).uniq
|
387
|
+
issue_release.update
|
388
|
+
success("Release #{version} finalizada com sucesso!")
|
389
|
+
end
|
390
|
+
|
391
|
+
def self.push_
|
392
|
+
push_origin
|
393
|
+
end
|
394
|
+
|
395
|
+
def self.push_origin
|
396
|
+
branch = !branch_name ? Git.execute { 'git branch --show-current' } : branch_name
|
397
|
+
branch.delete!("\n")
|
398
|
+
log_messages = Git.log_last_changes branch
|
399
|
+
issue_id = branch_name.to_s.match(/^(\d*)-/).to_a.last
|
400
|
+
issue = GitLab::Issue.find_by_id issue_id
|
401
|
+
Git.push branch
|
402
|
+
if log_messages != ''
|
403
|
+
print "Send messages commit for issue\n".yellow
|
404
|
+
issue.add_comment(log_messages)
|
405
|
+
end
|
406
|
+
|
407
|
+
remove_labels = $GIT_BRANCHES_STAGING + ['Staging', $GITLAB_NEXT_RELEASE_LIST]
|
408
|
+
old_labels = issue.obj_gitlab['labels']
|
409
|
+
old_labels.delete_if { |label| remove_labels.include? label }
|
410
|
+
|
411
|
+
issue.labels = old_labels + ['Doing']
|
412
|
+
issue.update
|
413
|
+
print "Success!\n\n".yellow
|
414
|
+
end
|
415
|
+
|
416
|
+
def self.set_error(e)
|
417
|
+
print "\n\n"
|
418
|
+
print TTY::Box.error(e.message, border: :light)
|
419
|
+
print e.backtrace
|
420
|
+
end
|
421
|
+
|
422
|
+
def self.validates
|
423
|
+
@@bar = bar
|
424
|
+
|
425
|
+
6.times do
|
426
|
+
# sleep(0.1)
|
427
|
+
@@bar.advance
|
428
|
+
end
|
429
|
+
if !$GITLAB_PROJECT_ID || !$GITLAB_TOKEN || !$GITLAB_URL_API ||
|
430
|
+
!$GIT_BRANCH_MASTER || !$GIT_BRANCH_DEVELOP || !$GITLAB_LISTS || !$GITLAB_NEXT_RELEASE_LIST
|
431
|
+
@@bar.stop
|
432
|
+
Menu.new.setup_variables
|
433
|
+
@@bar.finish
|
434
|
+
end
|
435
|
+
|
436
|
+
begin
|
437
|
+
branchs_validations = $GIT_BRANCHES_STAGING + [$GIT_BRANCH_MASTER, $GIT_BRANCH_DEVELOP]
|
438
|
+
Git.exist_branch?(branchs_validations.join(' '))
|
439
|
+
rescue StandardError => e
|
440
|
+
Git.checkout($GIT_BRANCH_MASTER)
|
441
|
+
|
442
|
+
begin
|
443
|
+
Git.new_branch($GIT_BRANCH_DEVELOP)
|
444
|
+
rescue StandardError
|
445
|
+
nil
|
446
|
+
end
|
447
|
+
begin
|
448
|
+
Git.push($GIT_BRANCH_DEVELOP)
|
449
|
+
rescue StandardError
|
450
|
+
nil
|
451
|
+
end
|
452
|
+
|
453
|
+
$GIT_BRANCHES_STAGING.each do |staging|
|
454
|
+
begin
|
455
|
+
Git.new_branch(staging)
|
456
|
+
rescue StandardError
|
457
|
+
nil
|
458
|
+
end
|
459
|
+
begin
|
460
|
+
Git.push(staging)
|
461
|
+
rescue StandardError
|
462
|
+
nil
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
2.times do
|
467
|
+
# sleep(0.1)
|
468
|
+
@@bar.advance
|
469
|
+
end
|
470
|
+
|
471
|
+
# Git.exist_branch?(branchs_validations.join(' ')) rescue raise "You need to create branches #{branchs_validations.join(', ')}"
|
472
|
+
|
473
|
+
2.times do
|
474
|
+
# sleep(0.1)
|
475
|
+
@@bar.advance
|
476
|
+
end
|
477
|
+
GitLab::Issue.ping
|
478
|
+
@@bar.finish
|
479
|
+
end
|
480
|
+
|
481
|
+
def self.reintegration(type = 'feature', branch_name)
|
482
|
+
# Git.fetch ref_branch
|
483
|
+
# Git.checkout ref_branch
|
484
|
+
# Git.pull ref_branch
|
485
|
+
|
486
|
+
source_branch = branch_name
|
487
|
+
has_parent_branch = branch_name.match?(/-#\d*/)
|
488
|
+
|
489
|
+
issue_id = branch_name.to_s.match(/^(\d*)-/).to_a.last
|
490
|
+
issue = GitLab::Issue.find_by_id issue_id
|
491
|
+
|
492
|
+
2.times do
|
493
|
+
sleep(0.2)
|
494
|
+
@@bar.advance
|
495
|
+
end
|
496
|
+
|
497
|
+
if has_parent_branch
|
498
|
+
|
499
|
+
parent_issue_id = branch_name.match(/-#(\d*)/)[1]
|
500
|
+
parent_issue = GitLab::Issue.find_by_id parent_issue_id
|
501
|
+
|
502
|
+
branchs_list = Git.execute { "git ls-remote --heads --refs | awk '{print $2}'" }
|
503
|
+
branchs_list = branchs_list.gsub('refs/heads/',
|
504
|
+
'').split("\n") - ($GIT_BRANCHES_STAGING + [$GIT_BRANCH_MASTER,
|
505
|
+
$GIT_BRANCH_DEVELOP])
|
506
|
+
parent_branch = branchs_list.detect { |i| i.match?(/^#{parent_issue_id}-*/) }
|
507
|
+
target_branch = parent_branch
|
508
|
+
Git.reset_hard target_branch, target_branch
|
509
|
+
@@bar.advance
|
510
|
+
Git.merge branch_name, target_branch
|
511
|
+
@@bar.advance
|
512
|
+
Git.push target_branch
|
513
|
+
@@bar.advance
|
514
|
+
|
515
|
+
issue.close
|
516
|
+
|
517
|
+
parent_issue.description += "\n* finalizada: ##{issue_id}"
|
518
|
+
parent_issue.update
|
519
|
+
|
520
|
+
success("\nFoi realizado o MERGE da branch #{branch_name} \ncom a branch pai #{target_branch}.\n\nA branch #{branch_name} e issue associada foram fechadas.")
|
521
|
+
else
|
522
|
+
|
523
|
+
# Setting Changelog
|
524
|
+
# print "Title: #{issue.title}\n\n"
|
525
|
+
# print "CHANGELOG message:\n--> ".yellow
|
526
|
+
@@bar.finish
|
527
|
+
message_changelog = prompt.ask('Informe a mensagem de CHANGELOG:', require: true, default: issue.title)
|
528
|
+
# message_changelog = STDIN.gets.chomp.to_s.encode('UTF-8')
|
529
|
+
# print "\n ok!\n\n".green
|
530
|
+
new_labels = []
|
531
|
+
if type == 'hotfix'
|
532
|
+
begin
|
533
|
+
!source_branch.match('hotfix')
|
534
|
+
rescue StandardError
|
535
|
+
raise 'Branch inválida!'
|
536
|
+
end
|
537
|
+
new_labels << 'hotfix'
|
538
|
+
new_labels << 'urgent'
|
539
|
+
else
|
540
|
+
begin
|
541
|
+
(!source_branch.match('feature') && !source_branch.match('bugfix'))
|
542
|
+
rescue StandardError
|
543
|
+
raise 'invalid branch!'
|
544
|
+
end
|
545
|
+
end
|
546
|
+
remove_labels = $GIT_BRANCHES_STAGING + $GITLAB_LISTS + ['Staging']
|
547
|
+
new_labels << 'changelog'
|
548
|
+
new_labels << $GITLAB_NEXT_RELEASE_LIST
|
549
|
+
old_labels = issue.obj_gitlab['labels']
|
550
|
+
old_labels.delete_if { |label| remove_labels.include? label }
|
551
|
+
issue.labels = (old_labels + new_labels).uniq
|
552
|
+
issue.description.gsub!(/\* ~changelog .*\n?/, '')
|
553
|
+
issue.description = "#{issue.description} \n* ~changelog #{message_changelog}"
|
554
|
+
|
555
|
+
# Setting Tasks
|
556
|
+
tasks = prompt.ask('Informe a lista de scripts ou tasks (opcional):')
|
557
|
+
|
558
|
+
issue.update
|
559
|
+
success("#{branch_name} foi finalizada e transferida por #{$GITLAB_NEXT_RELEASE_LIST} com sucesso!")
|
560
|
+
|
561
|
+
end
|
562
|
+
end
|
563
|
+
|
564
|
+
def self.start(branch, issue, ref_branch = $GIT_BRANCH_DEVELOP, parent_branch_name)
|
565
|
+
2.times do
|
566
|
+
sleep(0.2)
|
567
|
+
@@bar.advance
|
568
|
+
end
|
569
|
+
Git.checkout ref_branch
|
570
|
+
description = "* ~default_branch #{branch}\n"
|
571
|
+
description += "* ~parent #{parent_branch_name}\n" if parent_branch_name
|
572
|
+
issue.description = description
|
573
|
+
issue.update
|
574
|
+
2.times do
|
575
|
+
sleep(0.2)
|
576
|
+
@@bar.advance
|
577
|
+
end
|
578
|
+
Git.new_branch branch
|
579
|
+
Git.push branch
|
580
|
+
|
581
|
+
@@bar.finish
|
582
|
+
prompt.say(pastel.cyan("Você está na branch: #{branch}"))
|
583
|
+
success("Issue criada com sucesso!\nURL: #{issue.web_url}")
|
584
|
+
issue
|
585
|
+
# print "\nYou are on branch: #{branch}\n\n".yellow
|
586
|
+
end
|
587
|
+
|
588
|
+
def self.codereview(branch_name)
|
589
|
+
Git.checkout $GIT_BRANCH_DEVELOP
|
590
|
+
source_branch = branch_name
|
591
|
+
issue_id = branch_name.to_s.match(/^(\d*)-/).to_a.last
|
592
|
+
issue = GitLab::Issue.find_by_id issue_id
|
593
|
+
# issue.move
|
594
|
+
mr = GitLab::MergeRequest.new(
|
595
|
+
source_branch: source_branch,
|
596
|
+
target_branch: $GIT_BRANCH_DEVELOP,
|
597
|
+
issue_iid: issue.iid
|
598
|
+
)
|
599
|
+
mr.create_code_review
|
600
|
+
issue.labels = (issue.obj_gitlab['labels'] + ['code_review']).uniq
|
601
|
+
issue.update
|
602
|
+
end
|
603
|
+
|
604
|
+
def self.staging(branch_name)
|
605
|
+
branch = branch_name
|
606
|
+
issue_id = branch_name.to_s.match(/^(\d*)-/).to_a.last
|
607
|
+
issue = GitLab::Issue.find_by_id(issue_id)
|
608
|
+
|
609
|
+
prompt.say(pastel.cyan("\nVamos lá!"))
|
610
|
+
target_branch = prompt.select("\nEscolha a branch de homologação:", $GIT_BRANCHES_STAGING,
|
611
|
+
symbols: { marker: '>' }, filter: true)
|
612
|
+
|
613
|
+
options = []
|
614
|
+
options << { name: 'Limpar primeiro a branch e depois fazer o merge', value: :clear }
|
615
|
+
options << { name: 'Somente fazer o merge', value: :only_merge }
|
616
|
+
option_merge = prompt.select("\nO que deseja fazer?", options, symbols: { marker: '>' }, filter: true)
|
617
|
+
@@bar = bar('Realizando merge da branch em homologação')
|
618
|
+
@@bar.start
|
619
|
+
2.times do
|
620
|
+
sleep(0.2)
|
621
|
+
@@bar.advance
|
622
|
+
end
|
623
|
+
|
624
|
+
if option_merge == :clear
|
625
|
+
2.times do
|
626
|
+
sleep(0.2)
|
627
|
+
@@bar.advance
|
628
|
+
end
|
629
|
+
issues_staging = GitLab::Issue.from_list(target_branch).select { |i| i.branch != branch }
|
630
|
+
issues_staging.each do |i|
|
631
|
+
i.labels.delete(target_branch)
|
632
|
+
i.labels.delete('Staging')
|
633
|
+
i.labels.push('Doing')
|
634
|
+
i.update
|
635
|
+
end
|
636
|
+
@@bar.advance
|
637
|
+
Git.reset_hard branch, target_branch
|
638
|
+
@@bar.advance
|
639
|
+
Git.push_force target_branch
|
640
|
+
|
641
|
+
elsif option_merge == :only_merge
|
642
|
+
Git.reset_hard target_branch, target_branch
|
643
|
+
@@bar.advance
|
644
|
+
Git.merge branch, target_branch
|
645
|
+
@@bar.advance
|
646
|
+
Git.push target_branch
|
647
|
+
@@bar.advance
|
648
|
+
else
|
649
|
+
@@bar.stop
|
650
|
+
raise 'Escolha inválida'
|
651
|
+
end
|
652
|
+
|
653
|
+
new_labels = [target_branch, 'Staging']
|
654
|
+
remove_labels = $GITLAB_LISTS
|
655
|
+
old_labels = issue.obj_gitlab['labels']
|
656
|
+
old_labels.delete_if { |label| remove_labels.include? label }
|
657
|
+
issue.labels = (old_labels + new_labels).uniq
|
658
|
+
issue.update
|
659
|
+
@@bar.finish
|
660
|
+
# self.codereview branch_name
|
661
|
+
Git.checkout(branch)
|
662
|
+
prompt.say "\n"
|
663
|
+
success('Merge em homologação realizado com sucesso')
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|