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.6.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_staging ⇒ Object
- .hotfix_start ⇒ Object
- .install_ ⇒ Object
- .push_ ⇒ Object
- .push_origin ⇒ Object
- .release_finish ⇒ Object
- .release_start ⇒ Object
- .uninstall_ ⇒ Object
Class Method Details
.bugfix_codereview ⇒ Object
108 109 110 111 112 113 |
# File 'lib/sflow.rb', line 108 def self.bugfix_codereview if (!$PARAM1.match(/\-bugfix\//)) raise "This branch is not a bugfix" end self.codereview() end |
.bugfix_finish ⇒ Object
86 87 88 |
# File 'lib/sflow.rb', line 86 def self.bugfix_finish self.bugfix_reintegration end |
.bugfix_reintegration ⇒ Object
79 80 81 82 83 84 |
# File 'lib/sflow.rb', line 79 def self.bugfix_reintegration if (!$PARAM1.match(/\-bugfix\//)) raise "This branch is not a bugfix" end self.reintegration 'bugfix' end |
.bugfix_staging ⇒ Object
122 123 124 125 126 127 |
# File 'lib/sflow.rb', line 122 def self.bugfix_staging if (!$PARAM1.match(/\-bugfix\//)) raise "This branch is not a bugfix" end self.staging end |
.bugfix_start ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/sflow.rb', line 52 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sflow.rb', line 28 def self.call begin print "GitSflow #{VERSION}\n".green print "Loading...\n".yellow git_branch = Git.execute { "git branch --show-current" } print "\nYou are on branch:".yellow print " #{git_branch}\n".green validates if !['config_', 'help_'].include? ("#{$TYPE}_#{$ACTION}") # send("#{$TYPE}_#{$ACTION}") rescue => e set_error e end end |
.feature_codereview ⇒ Object
101 102 103 104 105 106 |
# File 'lib/sflow.rb', line 101 def self.feature_codereview if (!$PARAM1.match(/\-feature\//)) raise "This branch is not a feature" end self.codereview() end |
.feature_finish ⇒ Object
68 69 70 |
# File 'lib/sflow.rb', line 68 def self.feature_finish self.feature_reintegration end |
.feature_reintegration ⇒ Object
72 73 74 75 76 77 |
# File 'lib/sflow.rb', line 72 def self.feature_reintegration if (!$PARAM1.match(/\-feature\//)) raise "This branch is not a feature" end self.reintegration 'feature' end |
.feature_staging ⇒ Object
129 130 131 132 133 134 |
# File 'lib/sflow.rb', line 129 def self.feature_staging if (!$PARAM1.match(/\-feature\//)) raise "This branch is not a feature" end self.staging end |
.feature_start ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/sflow.rb', line 43 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
97 98 99 |
# File 'lib/sflow.rb', line 97 def self.hotfix_finish self.hotfix_reintegration end |
.hotfix_reintegration ⇒ Object
90 91 92 93 94 95 |
# File 'lib/sflow.rb', line 90 def self.hotfix_reintegration if (!$PARAM1.match(/\-hotfix\//)) raise "This branch is not a hotfix" end self.reintegration 'hotfix' end |
.hotfix_staging ⇒ Object
115 116 117 118 119 120 |
# File 'lib/sflow.rb', line 115 def self.hotfix_staging if (!$PARAM1.match(/\-hotfix\//)) raise "This branch is not a hotfix" end self.staging end |
.hotfix_start ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/sflow.rb', line 60 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
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/sflow.rb', line 359 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_ ⇒ Object
377 378 379 |
# File 'lib/sflow.rb', line 377 def self.push_ self.push_origin end |
.push_origin ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/sflow.rb', line 381 def self.push_origin branch = !$PARAM1 ? Git.execute { 'git branch --show-current' } : $PARAM1 branch.delete!("\n") = 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 |
# 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 #{$GIT_BRANCH_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
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 161 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 136 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 ready issues for start release" 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 card was created previously. 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 d_split = $SFLOW_TEMPLATE_RELEASE_DATE_FORMAT.split('/') date = Date.today.strftime("%#{d_split[0]}/%#{d_split[1]}/%#{d_split[2]}") version_header = "#{$SFLOW_TEMPLATE_RELEASE.gsub("{version}", version).gsub("{date}",date)}\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 msgs_changelog << "\n" 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" issue_release.labels = ['ready_to_deploy', 'Next Release'] issue_release.set_default_branch(release_branch) print "\n\nTasks list:\n\n".yellow tasks = [] issues.each do |issue| if issue.description.match(/(\* \~tasks .*)+/) tasks << "* ~tasks #{issue.list_tasks} \n" end end if tasks.size > 0 new_labels << 'tasks' tasks.each do |task| task = "#{task.strip.chomp.gsub('* ~tasks ', ' - ')}\n" print task.light_blue end issue_release.description += "#{tasks.join("")}\n" end 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 issue_release.description += "* #{issues.map{|i| "##{i.iid},"}.join(' ')}" issue_release.update rescue => exception Git.delete_branch(release_branch) raise exception. end end |
.uninstall_ ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/sflow.rb', line 345 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 |