Class: SFlow
- Inherits:
-
Object
- Object
- SFlow
- Defined in:
- lib/sflow.rb
Overview
require ‘./lib/gitlab/issue.rb’ require ‘./lib/gitlab/merge_request.rb’
Constant Summary collapse
- VERSION =
"0.4.3"
Class Method Summary collapse
- .bugfix_codereview ⇒ Object
- .bugfix_finish ⇒ Object
- .bugfix_reintegration ⇒ Object
- .bugfix_staging ⇒ Object
- .bugfix_start ⇒ Object
- .call ⇒ Object
- .feature_codereview ⇒ Object
- .feature_finish ⇒ Object
- .feature_reintegration ⇒ Object
- .feature_staging ⇒ Object
- .feature_start ⇒ Object
- .hotfix_finish ⇒ Object
- .hotfix_reintegration ⇒ Object
- .hotfix_start ⇒ Object
- .install_ ⇒ Object
- .push_origin ⇒ Object
- .release_finish ⇒ Object
- .release_start ⇒ Object
- .uninstall_ ⇒ Object
Class Method Details
.bugfix_codereview ⇒ Object
103 104 105 106 107 108 |
# File 'lib/sflow.rb', line 103 def self.bugfix_codereview if (!$PARAM1.match(/\-bugfix\//)) raise "This branch is not a bugfix" end self.codereview() end |
.bugfix_finish ⇒ Object
81 82 83 |
# File 'lib/sflow.rb', line 81 def self.bugfix_finish self.bugfix_reintegration end |
.bugfix_reintegration ⇒ Object
74 75 76 77 78 79 |
# File 'lib/sflow.rb', line 74 def self.bugfix_reintegration if (!$PARAM1.match(/\-bugfix\//)) raise "This branch is not a bugfix" end self.reintegration 'bugfix' end |
.bugfix_staging ⇒ Object
110 111 112 |
# File 'lib/sflow.rb', line 110 def self.bugfix_staging self.feature_staging end |
.bugfix_start ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/sflow.rb', line 47 def self.bugfix_start title = $PARAM2 == "" ? $PARAM1 : $PARAM2 issue = GitLab::Issue.new(title: title, labels: ['bugfix']) issue.create branch = "#{issue.iid}-bugfix/#{$PARAM1}" self.start(branch, issue) end |
.call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sflow.rb', line 27 def self.call begin print "Loading...\n".yellow validates if !['config_', 'help_'].include? ("#{$TYPE}_#{$ACTION}") # send("#{$TYPE}_#{$ACTION}") rescue => e set_error e end end |
.feature_codereview ⇒ Object
96 97 98 99 100 101 |
# File 'lib/sflow.rb', line 96 def self.feature_codereview if (!$PARAM1.match(/\-feature\//)) raise "This branch is not a feature" end self.codereview() end |
.feature_finish ⇒ Object
63 64 65 |
# File 'lib/sflow.rb', line 63 def self.feature_finish self.feature_reintegration end |
.feature_reintegration ⇒ Object
67 68 69 70 71 72 |
# File 'lib/sflow.rb', line 67 def self.feature_reintegration if (!$PARAM1.match(/\-feature\//)) raise "This branch is not a feature" end self.reintegration 'feature' end |
.feature_staging ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/sflow.rb', line 114 def self.feature_staging branch = $PARAM1 issue = GitLab::Issue.find_by_branch(branch) print "Staging branches list:\n\n".yellow print "----------------------------\n".blue $GIT_BRANCHES_STAGING.each_with_index do |staging, index| print "#{index} - #{staging}\n".blue end print "----------------------------\n".blue print "Choice number of target branch:\n".yellow target_branch_id = STDIN.gets.chomp print "\n#{target_branch_id}, " target_branch = $GIT_BRANCHES_STAGING[target_branch_id.to_i] if !$GIT_BRANCHES_STAGING.include?(target_branch) raise "option invalid!" end print "ok!\n".green print "\nAttention: \n".yellow.bg_red print "Do you want clean first the target branch or only merge?\n\n".yellow print "----------------------------\n".blue print "0 - Clean it first, then do merge #{branch} into #{target_branch}\n".blue print "1 - Only Merge: Merge #{branch} into #{target_branch}\n".blue print "----------------------------\n".blue print "Choice number of target branch:\n".yellow option_merge = STDIN.gets.chomp print "\n#{option_merge}, " print "ok!\n".green if option_merge == "0" Git.reset_hard branch, target_branch elsif option_merge == "1" Git.merge branch, target_branch else raise "Wrong choice" end new_labels = [target_branch, 'Staging'] remove_labels = $GITLAB_LISTS old_labels = issue.obj_gitlab["labels"] old_labels.delete_if{|label| remove_labels.include? label} issue.labels = (old_labels + new_labels).uniq issue.update self.codereview end |
.feature_start ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/sflow.rb', line 38 def self.feature_start title = $PARAM2 == "" ? $PARAM1 : $PARAM2 issue = GitLab::Issue.new(title: title, labels: ['feature']) issue.create branch = "#{issue.iid}-feature/#{$PARAM1}" self.start(branch, issue) end |
.hotfix_finish ⇒ Object
92 93 94 |
# File 'lib/sflow.rb', line 92 def self.hotfix_finish self.hotfix_reintegration end |
.hotfix_reintegration ⇒ Object
85 86 87 88 89 90 |
# File 'lib/sflow.rb', line 85 def self.hotfix_reintegration if (!$PARAM1.match(/\-hotfix\//)) raise "This branch is not a hotfix" end self.reintegration 'hotfix' end |
.hotfix_start ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/sflow.rb', line 55 def self.hotfix_start title = $PARAM2 == "" ? $PARAM1 : $PARAM2 issue = GitLab::Issue.new(title: title, labels: ['hotfix', 'production']) issue.create branch = "#{issue.iid}-hotfix/#{$PARAM1}" self.start(branch, issue, $GIT_BRANCH_MASTER) end |
.install_ ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/sflow.rb', line 360 def self.install_ puts "\n\nInstalling git alias\n\n".yellow print " \u{1F611} git sflow alias" print " (instaling...) \r".yellow GitLab.create_labels sleep 2 system("git config --local alias.sflow '!sh -c \" sflow $1 $2 $3 $4\" - '") print " \u{1F601}\ git sflow alias" print " (instaled) \u{2714} ".green print "\n\n" print "git sflow help\n\n" print "git sflow config\n\n" print "GitSFlow installed with success!\n\n".green # self.help_ # self.config_ end |
.push_origin ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/sflow.rb', line 379 def self.push_origin branch = $PARAM1 = Git.log_last_changes branch issue = GitLab::Issue.find_by_branch branch Git.push branch if ( != "") print "Send messages commit for issue\n".yellow issue.add_comment() end remove_labels = $GIT_BRANCHES_STAGING + ['Staging', $GITLAB_NEXT_RELEASE_LIST] old_labels = issue.obj_gitlab["labels"] old_labels.delete_if{|label| remove_labels.include? label} issue.labels = old_labels + ['Doing'] issue.update print "Success!\n\n".yellow end |
.release_finish ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/sflow.rb', line 297 def self.release_finish version = $PARAM1 if !version raise "param 'VERSION' not found" end new_labels = [] release_branch = "-release/#{version}" issue_release = GitLab::Issue.find_by_branch(release_branch) Git.merge issue_release.branch, 'develop' Git.push 'develop' type = issue_release.labels.include?('hotfix') ? 'hotfix' : nil mr_master = GitLab::MergeRequest.new( source_branch: issue_release.branch, target_branch: $GIT_BRANCH_MASTER, issue_iid: issue_release.iid, title: "Reintegration release #{version}: #{issue_release.branch} into master", description: "Closes ##{issue_release.iid}", type: type ) mr_master.create # end # mr_develop = GitLab::MergeRequest.new( # source_branch: issue_release.branch, # target_branch: 'develop', # issue_iid: issue_release.iid, # title: "##{issue_release.iid} - #{version} - Reintegration #{issue_release.branch} into develop", # type: 'hotfix' # ) # mr_develop.create # remove_labels = [$GITLAB_NEXT_RELEASE_LIST] remove_labels = [] old_labels = issue_release.obj_gitlab["labels"] + ['merge_request'] old_labels.delete_if{|label| remove_labels.include? label} issue_release.labels = (old_labels + new_labels).uniq issue_release.update print "\nRelease #{version} finished with success!\n\n".yellow end |
.release_start ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/sflow.rb', line 162 def self.release_start version = $PARAM1 if !version raise "param 'VERSION' not found" end issues = GitLab::Issue.from_list($GITLAB_NEXT_RELEASE_LIST).select{|i| !i.labels.include? 'ready_to_deploy'} issues_total = issues.size if issues_total == 0 raise "Not exist issues ready for start release version" end issues_urgent = issues.select{|i| i.labels.include? 'urgent'} issues_urgent_total = issues_urgent.size issue_title = "Release version #{version}\n" issue_release = GitLab::Issue.find_by(title: issue_title) rescue nil if issue_release print "This issue already exists, do you want to continue using it? (y/n):".yellow.bg_red print"\n If you choose 'n', a new issue will be created!\n" print "\n" option = STDIN.gets.chomp else option = 'n' end if option == 'n' issue_release = GitLab::Issue.new(title: issue_title) issue_release.create end new_labels = [] changelogs = [] release_branch = "#{issue_release.iid}-release/#{version}" print "Creating release version #{version}\n" begin Git.delete_branch(release_branch) Git.checkout 'develop' Git.new_branch release_branch print "Issue(s) title(s): \n".yellow issues.each do |issue| print " -> #{issue.title}\n" end print "\n" # if issues_urgent_total > 0 print "Attention!".yellow.bg_red print "\n\nChoose an option for merge:\n".yellow print "----------------------------\n".blue print "#{"0".ljust(10)} - Only #{issues_urgent_total} hotfix/urgent issues\n".blue if issues_urgent_total > 0 print "#{"1".ljust(10)} - All #{issues_total} issues\n".blue print "----------------------------\n".blue print "Choice a number:\n".yellow option = STDIN.gets.chomp # else # option = "1" # end case option when "0" print "Issue(s) title(s): \n" issues_urgent.each do |issue| print " -> #{issue.title}\n" end issues_urgent.each do |issue| Git.merge(issue.branch, release_branch) changelogs << "* ~changelog #{issue.msg_changelog} \n" new_labels << 'hotfix' end issues = issues_urgent when "1" type = 'other' print "Next release has total (#{issues_total}) issues.\n\n".yellow print "Issue(s) title(s): \n".yellow issues.each do |issue| print " -> #{issue.title}\n" end issues.each do |issue| Git.merge(issue.branch, release_branch) changelogs << "* ~changelog #{issue.msg_changelog} \n" end else raise "option invalid!" end print "Changelog messages:\n\n".yellow version_header = "Release version #{version}\n" print version_header.blue msgs_changelog = [] changelogs.each do |clog| msg_changelog = "#{clog.strip.chomp.gsub('* ~changelog ', ' - ')}\n" msgs_changelog << msg_changelog print msg_changelog.light_blue end print "\nSetting changelog message in CHANGELOG\n".yellow sleep 2 system('touch CHANGELOG') file_changelog = IO.read 'CHANGELOG' IO.write 'CHANGELOG', version_header + msgs_changelog.join('') + file_changelog system('git add CHANGELOG') system("git commit -m 'update CHANGELOG version #{version}'") Git.push release_branch issue_release.description = "#{changelogs.join("")}\n * #{issues.map{|i| "##{i.iid},"}.join(' ')}" issue_release.labels = ['ready_to_deploy', 'Next Release'] issue_release.set_default_branch(release_branch) issue_release.update issues.each do |issue| issue.labels = (issue.labels + new_labels).uniq issue.close end print "\nYou are on branch: #{release_branch}\n".yellow print "\nRelease #{version} created with success!\n\n".yellow rescue => exception Git.delete_branch(release_branch) raise exception. end end |
.uninstall_ ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/sflow.rb', line 346 def self.uninstall_ puts "\n\Uninstall git alias\n\n".yellow print " \u{1F611} git sflow alias" print " (removing...) \r".yellow sleep 2 system('git config --local --unset alias.sflow') print " \u{1F601}\ git sflow alias" print " (removed) \u{2714} ".green print "\n\n" print "Bye Bye" print "\n\n" end |