#!/usr/bin/env ruby require 'rubygems' require 'gitscape' require "optparse" OVERVIEW = <<-EOS gitscape perform git-related promotions in a consistent manner. The following actions are supported. bugfix_start Creates a branch off master called feature/ feature_start Creates a branch off the latest release branch called bugfix/ hotfix_start Creates a branch off live called hotfix/ feature_finish [] Merges the branch feature/ into the master branch. When -u is specified, the master branch is copied to its corresponding tracking branch (staging). If is omitted and you are already on a feature branch, it is used. bugfix_finish [] Merges the branch bugfix/ into master and optionally into the current release branch (when --qa is specified). When -u is specified, any updated branch is copied to its corresponding tracking branch (master to staging, the current release branch to qa). If is omitted and you are already on a bugfix branch, it is used. hotfix_finish [] Merges the branch hotfix/ into master, optionally into the current branch (when --qa or --live is specified) and to the live branch (when --live is specified). When -u is specified, any updated branch is copied to its corresponding tracking branch (master to staging, the current release branch to qa). If is omitted and you are already on a hotfix branch, it is used. release_start Branches master, incrementing the release number to create a new release branch, release/i. The release branch is forced to the qa branch. ** These actions update the origin server. ** release_finish After performing several validations, it merges the latest release branch into live and master. Tags are created that facilitate a rollback. ** These actions update the origin server. ** EOS # Parse option overrides. options = {} op = OptionParser.new do |op| op.banner = 'Usage: gitscape [action] [options]' op.separator('Options:') op.on '--[no-]trace', 'Verbose output for debugging' do |bool| options[:trace] = bool end op.on '-h', '--help', 'Show a list of actions' do puts OVERVIEW exit end op.on '-p', '--[no-]push', 'Whether or not to push changes to origin' do |bool| options[:push] = bool end op.on '-u', '--[no-]update-env', 'Whether to update environment branches when their development branch is updated' do |bool| options[:update_env] = bool end op.on '-e', '--env-depth=ENV', [:staging, :qa, :live], 'The level of environments to push changes to' do |depth| options[:env_depth] = depth end op.on '--qa', 'Sets the environment depth for the command to the qa environment' do options[:env_depth] = :qa end op.on '--live', 'Sets the environment depth for the command to the live environment' do options[:env_depth] = :live end end op.parse!(ARGV) if ARGV.size < 1 puts OVERVIEW exit else command_name = ARGV[0] case command_name when "bugfix_start", "feature_start", "hotfix_start" branch_name = ARGV[1] Gitscape::Base.new.send command_name, branch_name, options when "bugfix_finish", "feature_finish", "hotfix_finish" branch_name = ARGV[1] Gitscape::Base.new.send command_name, branch_name, options when "release_start" Gitscape::Base.new.release_start options when "release_finish" Gitscape::Base.new.release_finish options when "tag_cleanup" Gitscape::Base.new.tag_cleanup options else puts "Unknown command: #{command_name}" end end