diff --git a/lib/heroku_feature_deployments/deployer.rb b/lib/heroku_feature_deployments/deployer.rb index 0727075..dad0f56 100644 --- a/lib/heroku_feature_deployments/deployer.rb +++ b/lib/heroku_feature_deployments/deployer.rb @@ -1,6 +1,8 @@ module HerokuFeatureDeployments class Deployer + attr :pivotal_ticket_id + def initialize(options = {}) @branch_name = options[:branch_name] || get_branch_name @remote_name = options[:remote_name] || @branch_name.underscore @@ -15,8 +17,11 @@ def initialize(options = {}) # PivotalTracker::Client.token = config.pivotal_tracker_api_key end - def deploy(pivotal_ticket_id) - @pivotal_ticket_id = pivotal_ticket_id + # options + # :pivotal_ticket_id - if nil, ticket id will be fetched from branch + # name. + def deploy(options = {}) + @pivotal_ticket_id = options[:pivotal_ticket_id] if app_exists? add_environment_variables add_collaborators @@ -85,8 +90,13 @@ def create_pull_request # end def get_branch_name - `git branch`.split("\n").select {|s| s =~ /\*/ }.first.gsub(/\*/, ''). - strip + `git rev-parse --abbrev-ref HEAD`.strip + end + + # Default to ticket id from branch name in format: + # "48586573-pg-tags" -> "48586573". + def pivotal_ticket_id(branch_name = get_branch_name) + @pivotal_ticket_id ||= ((branch_name =~ /^(\d+)/ rescue false) ? $1 : nil) end def create_db diff --git a/lib/tasks/heroku_feature_deployments.rake b/lib/tasks/heroku_feature_deployments.rake index aa11cb2..21a1302 100644 --- a/lib/tasks/heroku_feature_deployments.rake +++ b/lib/tasks/heroku_feature_deployments.rake @@ -2,8 +2,7 @@ namespace :hfd do desc 'Deploy the current branch' task deploy: :environment do - HerokuFeatureDeployments::Deployer.new. - deploy(ENV['PIVOTAL_TICKET_ID']) + HerokuFeatureDeployments::Deployer.new.deploy(ENV['PIVOTAL_TICKET_ID']) end desc 'Undeploy the current branch'