gitsflow 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gitsflow might be problematic. Click here for more details.

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